Giter VIP home page Giter VIP logo

esp8266_p1meter's Introduction

esp8266_p1meter

Software for the ESP2866 that sends P1 smart meter data to an mqtt broker (with OTA firmware updates)

08-05-2021: I've not used this sketch myself for several years now and as such it became a bit outdated: It supports only older meters with version 2.2 and 2.0 and the development has halted. I recommend people with newer meters to have a look at this fork instead.

Connection of the P1 meter to the ESP8266

ESP8266 Pin P1 Pin
GND GND
3V3 RTS
DATA (RXD) D2

To connect my Landys and Gyr E350 (ZCF110), I used a 10K resistor connected between DATA (RXD) and RTS. Many howto's mention RTS requires 5V (VIN) to activate the P1 port, but for me 3V3 suffices.

RJ11 P1 connetor

Data Sent

All metrics are send to their own MQTT topic. The nodemcu sends out to the following MQTT topics:

sensors/power/p1meter/consumption_low_tarif 2209397
sensors/power/p1meter/consumption_high_tarif 1964962
sensors/power/p1meter/actual_consumption 313
sensors/power/p1meter/instant_power_usage 313
sensors/power/p1meter/instant_power_current 1000
sensors/power/p1meter/gas_meter_m3 968922
sensors/power/p1meter/actual_tarif_group 2
sensors/power/p1meter/short_power_outages 3
sensors/power/p1meter/long_power_outages 1
sensors/power/p1meter/short_power_drops 0
sensors/power/p1meter/short_power_peaks 0

As I don't have solar panels (yet) I do not collect the data for power returns as I don't have any. They are however easy to add if you know the codes used.

Home Assistant Configuration

I use this for home assistant sensors.yaml:

- platform: mqtt
  name: P1 Consumption Low Tarif
  unit_of_measurement: 'kWh'
  state_topic: "sensors/power/p1meter/consumption_low_tarif"
  value_template: "{{ value|float / 1000 }}"

- platform: mqtt
  name: P1 Consumption High Tarif
  unit_of_measurement: 'kWh'
  state_topic: "sensors/power/p1meter/consumption_high_tarif"
  value_template: "{{ value|float / 1000 }}"

- platform: mqtt
  name: P1 Actual Power Consumption
  unit_of_measurement: 'kW'
  state_topic: "sensors/power/p1meter/actual_consumption"
  value_template: "{{ value|float / 1000 }}"

- platform: mqtt
  name: P1 Instant Power Usage
  unit_of_measurement: 'kW'
  state_topic: "sensors/power/p1meter/instant_power_usage"
  value_template: "{{ value|float / 1000 }}"

- platform: mqtt
  name: P1 Instant Power Current
  unit_of_measurement: 'A'
  state_topic: "sensors/power/p1meter/instant_power_current"
  value_template: "{{ value|float / 1000 }}"

- platform: mqtt
  name: P1 Gas Usage
  unit_of_measurement: 'm3'
  state_topic: "sensors/power/p1meter/gas_meter_m3"
  value_template: "{{ value|float / 1000 }}"

- platform: mqtt
  name: P1 Actual Tarif Group
  state_topic: "sensors/power/p1meter/actual_tarif_group"

- platform: mqtt
  name: P1 Short Power Outages
  state_topic: "sensors/power/p1meter/short_power_outages"

- platform: mqtt
  name: P1 Long Power Outages
  state_topic: "sensors/power/p1meter/long_power_outages"

- platform: mqtt
  name: P1 Short Power Drops
  state_topic: "sensors/power/p1meter/short_power_drops"

- platform: mqtt
  name: P1 Short Power Peaks
  state_topic: "sensors/power/p1meter/short_power_peaks"

The automations are yours to create. And always remember that sending alerts in case of a power outtage only make sense when you own a UPS battery :)

Thanks to

This sketch is mostly copied and pasted from several other projects. Standing on the heads of giants, big thanks and great respect to the writers and/or creators of:

esp8266_p1meter's People

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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp8266_p1meter's Issues

WDT-reset

First of all: thanks for the great work!

My Wemos D1 Mini had a lot of WDT-resets while running this code. After I changed read_p1_serial() to disable the watchdog during serial-reading it stopped resetting. I guess the data that is transferred is too large/takes too long.

Maybe it works for other people as well.

       while (p1_serial.available())
        {
          ESP.wdtDisable ();
            int len = p1_serial.readBytesUntil('\n', telegram, P1_MAXLINELENGTH);
          ESP.wdtEnable (1);
etc...

Compiling

It would be nice if you can update the code to work with the new board database and the SoftwareSerial that is included. Now we get build errors.

Your Github is linked by homeassistant so would be nice to have an up to date code.
Im by no name a programmer and can not fix the problem on my own.
A list of the used github / libraries (including the makers) would be nice

I used arduino 1.8.10
Board Manager from https://arduino.esp8266.com/stable/package_esp8266com_index.json

Switch to hardware serial for DSMR5 compatibility?

First off, thanks for your work on this library ๐Ÿ‘

Using it I was running into issues with my Landys and Gyr E360 meter. The problem I ran into was that all received telegrams would have some form of corruption (often a couple of missing characters) causing the CRC validation to fail. I think this is due to the 1 second interval of telegrams in DSMR5 just being to much.

Some background

After a lengthy investigation I can conclude that my problem is caused by the software serial simply not being able to keep up with the barrage of incoming messages.

So far I have learned:

  • Disabling everything (Wifi, MQTT, etc) allows me to receive about 30% of all telegrams using SoftwareSerial. But this limits the usefulness of this library ๐Ÿ˜œ
  • Connecting the RTS pin to a ESP8266 IO pin and only activating the P1 meter on interval allows me to receive about 5% of all telegrams correctly. I think this helps the SoftwareSerial to keep up pace. But I am afraid that users with longer telegrams (i.e. when using a 3 phase power supply) will have a much lower success rate.
  • Removing delays or watchdog calls allowed for small improvements at the cost of overall stability

This finally made me give up on SoftwareSerial for DSMR5.0.

Hardware Serial

Luckily it is has become possible to run the Esp8266's HardwareSerial with inversion. One major limitation is that inversion is only supported for Uart0, which is also used for USB serial logging (at least on my D1 mini).

I have created a fork where I got the HardwareSerial working, and all DSMR5.0 telegrams now pass CRC validation. But this is at the cost of no longer being able to read serial log data from the USB serial monitor in the Arduino IDE.

Now I have arrived at the point (not just the point of this lengthy message ๐Ÿ˜‰) where I want to offer these changes back to your library as a PR. But think I first need to fix the logging.

This leads me tot he following questions:

  • Are you interested in changing the library to use the Hardware serial, or would you rather I keep and maintain it myself as a fork?
  • I'm thinking of changing the logging to use some form of storage and some form of network messaging (basic UDP, Telnet, Mqtt, HTTP webserver) to deal with the unavailability of the USB serial monitor. Do you have any preferences or opinions on this matter before I start work on this?

Update 2020-06-12: I have been able to get the USB serial monitoring working by doing some crazy cool esp8266 register call

Compiling in Arduino IDE

It seems that some default libraries are changed. Ik had a view errors when compiling the code and uploading it to the ESP.
Two main errors were:

  1. using double WifiUDP
  2. method not found

I changed the includes to this:
#include <FS.h>
#include <EEPROM.h>
// * #include <DNSServer.h>
#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <WiFiManager.h>
#include <ESP8266mDNS.h>
// * #include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <SoftwareSerial.h>

Telegram is always incomplete

Hi,

I have your esp8266_p1meter (the version from your development branch) running directly powered by the meter itself but I still have some issues:

  • I consistently miss the first lines of the telegram so line 1.0-1.8.1 & 1.0-1.8.2 are not being parsed.
  • CRC is never calculated correctly, also because I miss the first lines -> I overruled the CRC validation for testing
  • sometimes I read 0 values on the consumption counters (probably also by the missing lines AND no CRC validation)

So basically, I miss the first lines.

  • Could it bet that my pullup resistor has something to do with that? (not that familiar with these things)
  • Maybe the interval? it's set to run every 15seconds. I have bad results with 30s and 60s not sending anything at all....

No MQTT being sent and WDT-Resets

Hello, This is my first time doing anything with my smart meter and I've been trying to use esp8266_p1meter on my Wemos D1 Mini. At first I got a SoftwareSerial error and used #4 to fix it, Now I keep getting a bunch of WDT resets.

On top of all of that, I seem to be receiving data but nothing ever gets sent via MQTT.
My smart meter is an Agemcom T210-D.

Any help would be appreciated!

new lines contain to many characters

New lines contain to many characters, being the characters of previous longer lines.
therefor I moved the memset in the while loop so every line gets cleared after being read.

memset(telegram, 0, sizeof(telegram));

I edited this in my fork: https://github.com/jellevervloessem/esp8266_p1meter/blob/a90aae075a32996490c3d6374bd99bffcd4074da/esp8266_p1meter/esp8266_p1meter.ino#L482

Not sure, but I think this is also failing the CRC.

Maintainer is temporarily not using this project so issues and pull requests might be stale

For those interested in this project: I recently moved to a new home and as a result I'm at this moment not using this project myself. As soon as I've found a post-corona electrician willing to come to my home and create a power outlet next to my DSMR meter i can reinstall this project and fix bugs and add functionality.

In the meantime: Please fork and create a pull request with fixes if you stumble into repairable issues and manage to work around them. I will get back to you and merge your code changes in the coming months when I can use this project myself again.

Auto reconnect to WiFi

Hi,

I manage to have my setup yesterday and it worked fine until what it seems like around afternoon, then the WiFi connection dropped. (my meter is just outside of my apartment)

I even restarted my router while I was at the office but it didn't connect back so I didn't have data until I got back home, unplugged the esp and plugged it back.

Now it works fine but it most probably gonna happen again. Not really experienced in this but is it possible to put a control in the loop method, so if it's not connected to WiFi, it would reconnect?

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.