GithubHelp home page GithubHelp logo

mrebbert / ferrarispowermeter Goto Github PK

View Code? Open in Web Editor NEW
29.0 5.0 7.0 2.53 MB

A sensor for a ferraris energy meter based on an ESP8266 or similar including a HomeAssistant-Integration via MQTT.

License: GNU General Public License v3.0

C++ 100.00%
arduino esp8266 ferrariscounter home-assistant mqtt tcrt5000 oled display i2c wifimanager

ferrarispowermeter's Introduction

ESP - Ferraris Energy Meter with HomeAssistant MQTT Integration

A sensor for a ferraris energy meter based on an ESP8266 or similar including a HomeAssistant-Integration via MQTT.

Short Description

The general intention of this Arduino sketch is pretty straight forward: Read the rotations of the disc of a ferraris energy meter and calculate the actual power consumption in watts and the energy consumption of the day and in total in kWh. Write all these informations on MQTT topics which are discovered from Home Assistant automatically. Additionally it show the current information on an OLED display.

short description

The Software

Sketch

As already mentioned this Sketch bases on Arduino. I use the ESP8266 based Wemos D1 mini (R2) but i think you can use nearly every ESP-Microcontroller for it (not tested yet). To make the (or even my) life easier, it uses different fantastic libraries:

The usage of these libs is (more or less) encapsulated in corresponding own libraries, which are described (/TODO) here.

Most of it is running out-of-the-box. You may want to change your ntp server settings here.

MQTT

I use the Mosquitto Broker which fits my requirements perfectly. You can also find an official Docker Image of it. I recommend a GUI based client like MQTT Explorer or MQTT.fx for testing purposes.

Once the sensor is running, you'll find three new topics on your broker:

|-homeassistant
  |-MRT-Power-Meter-1234 (<-- the last digits are the chip id and can vary)
    |-energy: the configuration topic of the energy sensor(kWh)
    |-power: the configuration topic of the power sensor(W)
    |-state: the sensor payload

'energy' and 'power' contains the configuration payload for the sensors. This is neccessary so that the MQTT Discovery of Home Assistant integrate the sensors automatically. The payload is more or less static and the configuration is 'retain'.

{"device_class":"energy",
 "name":"MRT-Power-Meter-1234-Energy",
 "state_topic":"homeassistant/sensor/MRT-Power-Meter-1234/state",
 "json_attributes_topic":"homeassistant/sensor/MRT-Power-Meter-1234/state",
 "unique_id":"MRT-Power-Meter-1234-Energy-ESP",
 "unit_of_measurement":"kWh",
 "value_template":"{{value_json.total_energy_kwh}}"
}
{"device_class":"power",
 "name":"MRT-Power-Meter-1234-Power",
 "state_topic":"homeassistant/sensor/MRT-Power-Meter-1234/state",
 "json_attributes_topic":"homeassistant/sensor/MRT-Power-Meter-1234/state",
 "unique_id":"MRT-Power-Meter-1234-Power-ESP",
 "unit_of_measurement":"W",
 "value_template":"{{value_json.power}}"
}

The 'state' topics contains the current attributes of power and energy consumption.

{"node":"MRT-Power-Meter-1234",
 "total_energy_kwh":33548.9609375,
 "today_energy_kwh":12.373322486877441,
 "power":533.33331298828125
}

Home Assistant

The integration of the sensor data in Home Assistant is pretty straight forward. Once, the MQTT Integration is done, the sensors for Power (watts) and Energy (kWh) will be integrated automically with the first published configuration messages. I made use of the MQTT Discovery mechanism for that. If everything's fine, you'll find two new sensors in your entity list:

sensor.mrt_power_meter_1234_energy
sensor.mrt_power_meter_1234_power

Sensors in HA

To track the consumption in long term i personally use the Utility Meter in Home Assistant:


daily_energy_house:
  source: sensor.mrt_power_meter_1234_energy
  cycle: daily
weekly_energy_house:
  source: sensor.mrt_power_meter_1234_energy
  cycle: weekly
monthly_energy_house:
  source: sensor.mrt_power_meter_1234_energy
  cycle: monthly
yearly_energy_house:
  source: sensor.mrt_power_meter_1234_energy
  cycle: yearly

The Hardware

As mentioned before, i use the Wemos D1 mini for the development. But i'm sure, you can use every ESP based MCU. Shopping list: (de-amazon affiliate links)

The Wiring, Soldering and/or Fritzing

Prologue - Bouncing: The TCRT5000 delivers unclean signals

Actually it should be enough to connect the TCRT5000 with the D0 output to an input of the ESP8266. There are pretty much examples where an unclean signal is handled for example with a "bouncing time". For a better understanding: Bouncing is an effect that occurs with switches. When a switch is closed, the contacts often "bounce" against each other, so that the closed state only occurs after a few milliseconds. In between, the contacts jump on each other and create a series of open and closed states. A downstream electronic system can then erroneously register several events instead of one and behave correspondingly chaotically. This is exactly what happens with the TCRT5000. When the rotating disc of the power meter changes from the reflective silver state to the red bar, the TCRT5000 does not signal this reliably. In that case you have to calculate the signal cleanly via software. There are several reports of incorrect behaviour, because instead of counting one pulse when the states change, it counts at least two events. However, this does not allow consumption to be determined and you can forget about measuring consumption.

Schmitt Trigger

A very convinient solution for this is to use a so called 'Schmitt Trigger'. Just in short: A Schmitt trigger compares two voltages and delivers a clearly defined output state depending on the input level and switching threshold. This turns an undefined input signal into a beautifully clear output signal. Exactly what we need here. The IC 74HC14N includes 6 inverted Schmitt Trigger.

Wiring

The wiring is quite simple: The input of one of the 6 Schmitt triggers is provided with a 100 nF capacitor against ground and is connected to the D0 output of the TCRT5000 (I took the first pair: Pin 1 and 2). The output of the Schmitt trigger goes to the desired pin of the ESP8266 (D5 in my case). Pin 7 of the IC goes to GND and pin 14 to the 3.3 volts of the ESP8266. The display uses the I2C bus.

Fritzing Schaltplan

The Cases

I took some out-of-the-box cases from thingiverse here.

For the TCRT5000: https://www.thingiverse.com/thing:4560681

For the Wemos D1 mini including the board and display: https://www.thingiverse.com/thing:4371400

Important: For a better fit i scale this one 101% in the x- and y-achses and additionally the case (not the top) 150% in the Z-achses to have more space inside.

The Configuration

Once, everything is wired, the MCU could be configured. Initially it raises an access point which you can find with a wifi scan. The SSID starts with "MRT-Power-Meter...". Once connected, you can configure your settings.

  • Wifi SSID and Credentials
  • MQTT settings
  • Rotations per kWh: You can find the information, how many rotations of the disc means 1kWh, directly on the counter (i.e. 75 U/1kWh or similar).
  • Actual counter: You also can enter the actual count of your counter.

configscreen

If the input was correct the esp restarts and connects to the configured wifi. If the credentials of the wifi were wrong the AP starts again and you're able to re-enter your data. If you want delete your configuration you can push the reset button twice.

ferrarispowermeter's People

Contributors

mrebbert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ferrarispowermeter's Issues

How to install ?

can you provide the .bin to install on esp or how can i do it ?

Running on ESP32

I struggle to geht this working on an ESP32. When trying to build by platformio i get error, that ESP8266 WiFi Manager Library can not be found.

I edited the parameters in the platformio file. Any ideas what hast to be configured elsewhere to get it running on Esp32?

Client [MRT-Power-Meter-7691794] connection closed: timeout

Source Date Level Message
mqtt.0 2021-10-26 11:44:42.131 info Client [MRT-Power-Meter-7691794] connected with secret 1635241482130_4615
mqtt.0 2021-10-26 11:44:26.718 info Client [MRT-Power-Meter-7691794] connection closed: timeout

I see reconnects in the logs very often.
Does anyone else have these messages in their logs as well?

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.