Code Monkey home page Code Monkey logo

power_meter_mqtt's Introduction

Power Meter with mqtt-for devices with pulse output

About

This project presents a simple solution for measuring the energy consumption of a house. The key element is a cheap energy monitor with pulse output, connected to an ESP32 WROOM 32 board. This, over WiFi using mqtt protocol can be easily connected to a home automation system to report:

  • instant power (in Watt);
  • total power consumption (in kWh);
  • Device temperature (in Celsius) using a DS18b20 temperature sensor.

OTA support is enabled, after the first software upload, the ESP will available for updates on the local network over Arduino IDE.

Hardware Components

ESP 32 board

ESP32 WROOM 32 board

The Power Meter

The power meter adeleq_02-553_DIG operating range is 0.05A-45A, and (the most important part) provide 2000 impulses / kWh. Emitted pulses for detections have ~90 ms pulse width. The output is open collector, operating voltage, from 5-24V. In this case, the ESP32 supply provides 3.3V, but this is not a limitation. Other variants are available on the market, usually, the difference is the accuracy (i.e. pulses / kWh are only 1000 instead of 2000).

400

Below a sample picture for the output, where a light bulb (~53W) is connected to the power meter. The measured pulse between the two detections is about 30.71s, which leads to a value measured of ~58.61 Watts.
Conversion from kWh to Watts, measured with a sensor of 2000 pulses/ kWh:
(<kilo Watt to Watt>*<Hour in secounds>/<impuse number>)/<time measured between pulses> 
=>(1000*3600/2000)/31.71 => 58.71W

The temperature sensor

DS18b20 is a fast digital thermometer using 1-Wire protocol. The usual connection diagram is with a 4.7 kOhm pull-up resistor.

Connection diagramm

Below the wiring diagram, made with Easyeda tool. In noisy environments, the recommendation is to add a 33pf condensator between ground and energy sensor input pins (to avoid sporadic interrupts).

Final integration

400 400

How to use

Clone the repository, update the .ino file in Arduino IDE with your local WiFi / mqtt configuration.

/*mqtt declarations*/
const char* mqtt_server = "<IP OF THE MQTT SERVER>";
const char* mqtt_user = "<USER NAME>";
const char* mqtt_password = "<PASSWORD>";
...
/* SSID and Password of WiFi router */
const char* ssid = "<ROUTER SSID>";
const char* password = "<ROUTER PASSWORD>";

Upload the code in the ESP32 WROOM 32 board over USB, wire the board accordingly to the schematics. The output will be something similar on the mqtt topics:

400

Additionally the following mqtt commands can be used:
- topic: /pulseenergymonitor/cmd
- payload: c / r
  c - clear kWh information
  r - reset the device

Home Assistant integration

Home Assistant is an open source automatization system, with a high number of component integratios. Is a good choise for complex IOT and DIY smart home atomatization. Below a panel component and a log file which shows the sensor information and energy consumption.

400 400

Paste the following lines in the configuration.yaml file:

sensor:
  - platform: mqtt
    state_topic: "/pulseenergymonitor/watts"
    name: "Pulse Energy Monitor"
    icon: mdi:gauge
    unit_of_measurement: "W"
  - platform: mqtt
    state_topic: "/pulseenergymonitor/kWh"
    name: "PEM kWh"
    icon: mdi:gauge
    unit_of_measurement: "kWh"

Energy consumption measurement has a specific component in Home Assistant, the utility meter, past into configuration.yaml file.

##################################
# Utility meter
##################################

utility_meter:
  daily_energy:
    source: sensor.pem_kwh
    cycle: daily
  weekly_energy:
    source: sensor.pem_kwh
    cycle: weekly
  monthly_energy:
    source: sensor.pem_kwh
    cycle: monthly

/Enjoy.

power_meter_mqtt's People

Contributors

fvilmos avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.