Giter VIP home page Giter VIP logo

Comments (2)

psvanstrom avatar psvanstrom commented on June 26, 2024

Interesting, could be a parse problem. I will take a look 👍

from esphome-p1reader.

psvanstrom avatar psvanstrom commented on June 26, 2024

Ok, so checking the obis codes, this looks like a simple fix by just updating the code that parses the codes.

For example, you have two cumulative import / export values, one pair for rate 1 (1.8.1 / 2.8.1) and one for rate 2 (1.8.2 / 2.8.2) while the Swedish specification only have one rate (1.8.0 / 2.8.0).

The empty values such as '': Sending state 0.00000 with 0 decimals of accuracy are for the second and third phases that your meter doesn't have.

So what you can do is to define a couple of new sensors for rate 1 / rate 2 like this to the ParsedMessage class:

class ParsedMessage {
  public:
    double cumulativeActiveImportRate1;
    double cumulativeActiveImportRate2;
    double cumulativeActiveExportRate1;
    double cumulativeActiveExportRate2;
    ...

and to the P1Reader class:

  public:
    Sensor *cumulativeActiveImportRate1 = new Sensor();
    Sensor *cumulativeActiveImportRate2 = new Sensor();
    Sensor *cumulativeActiveExportRate1 = new Sensor();
    Sensor *cumulativeActiveExportRate2 = new Sensor();

update the parse logic:

void parseRow(ParsedMessage* parsed, char* obisCode, char* value) {
      if (strncmp(obisCode, "1.8.1", 5) == 0) {
        parsed->cumulativeActiveImportRate1 = atof(value);

      } else if (strncmp(obisCode, "1.8.2", 5) == 0) {
        parsed->cumulativeActiveImportRate2 = atof(value);

      } else if (strncmp(obisCode, "2.8.1", 5) == 0) {
        parsed->cumulativeActiveExportRate1 = atof(value);

      } else if (strncmp(obisCode, "2.8.2", 5) == 0) {
        parsed->cumulativeActiveExportRate2 = atof(value);
      ....

and finally add them to the yaml so that they are exposed as sensors:

sensor:
- platform: custom
  lambda: |-
    auto meter_sensor = new P1Reader(id(uart_bus));
    App.register_component(meter_sensor);
    return {
      meter_sensor->cumulativeActiveImportRate1,
      meter_sensor->cumulativeActiveExportRate2,
      meter_sensor->cumulativeActiveImportRate1,
      meter_sensor->cumulativeActiveExportRate2,
      ...

You could also remove all sensors and parse logic for the 2nd and 3rd phases as you don't have those: momentaryActiveImportL2, momentaryActiveImportL3 etc.

from esphome-p1reader.

Related Issues (20)

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.