alengwenus / esphome_components

External components for ESPHome
GNU General Public License v3.0
29 stars 9 forks source link

It decodes no more to SML #17

Closed NihilUnum closed 1 year ago

NihilUnum commented 1 year ago

Hi Alengwenus

I hope you can help me. I am fighting with my SGM-C4 electricity meter. Probably because it too new(?) I am getting great debug log

[uart_debug:114]:
1B:1B:1B:01:01:01:01:76:05:00:46:79:65:62:00:62:00:72:63:01:01:76:01:07:FF:FF:FF:FF:FF:FF:05:00:17:7D:CD:0B:0A:01:45:46:52:21:02:CF:69:49:72:62:01:65:01:FC:CF:FD:01:63:AE:A6:00:76:05:00:46:79:66:62:00:62:00:72:63:07:01:77:07:FF:FF:FF:FF:FF:FF:0B:0A:01:45:46:52:21:02:CF:69:49:07:01:00:62:0A:FF:FF:72:62:01:65:01:FC:CF:FD:F1:06:77:07:01:00:60:32:01:01:01:01:01:01:04:45:46:52:01:77:07:01:00:60:01:00:FF:01:01:01:01:0B:0A:01:45:46:52:21:02:CF:69:49:01:77:07:01:00:01:08:00:FF:64:1C:40:04:72:62:01:65:01:FC:CF:FD:62:1E:52:FF:65:02:67:8D:FD:01:77:07:01:00:02:08:00:FF:01:72:62:01:65:01:FC:CF:FD:62:1E:52:FF:64:07:41:8D:01:77:07:01:00:10:07:00:FF:01:01:62:1B:52:00:53:00:9F:01:77:07:01:00:20:07:00:FF:01:01:62:23:52:FF:63:09:26:01:77:07:01:00:34:07:00:FF:01:01:62:23:52:FF:63:09:4C:01:77:07:01:00:48:07:00:FF:01:01:62:23:52:FF:63:09:68:01:77:07:01:00:1F:07:00:FF:01:01:62:21:52:FE:62:97:01:77:07:01:00:33:07:00:FF:01:01:62:21:52:FE:62:8A:01:77:07:01:00:47:07:00:FF:01:01:62:21:52:FE:62:53:01:77:07:01:00:51:07:01:FF:01:01:62:08:52:00:53:00:F0:01:77:07:01:00:51:07:02:FF:01:01:62:08:52:00:52:77:01:77:07:01:00:51:07:04:FF:01:01:62:08:52:00:53:01:25:01:77:07:01:00:51:07:0F:FF:01:01:62:08:52:00:53:01:1C:01:77:07:01:00:51:07:1A:FF:01:01:62:08:52:00:53:01:06:01:77:07:01:00:0E:07:00:FF:01:01:62:2C:52:FF:63:01:F3:01:77:07:01:00:00:02:00:00:01:01:01:01:06:30:33:2E:30:30:01:77:07:01:00:60:5A:02:01:01:01:01:01:03:42:BD:01:77:07:01:00:61:61:00:00:01:01:01:01:03:00:00:01:77:07:01:00:60:32:01:04:01:01:01:01:08:50:31:2E:32:2E:31:32:01:77:07:01:00:60:32:04:04:01:01:01:01:03:04:22:01:01:01:63:0E:C9:00:76:05:00:46:79:67:62:00:62:00:72:63:02:01:71:01:63:7C:0F:00:00:1B:1B:1B:1B:1A:01:24:82

So I think hard ware is not a issue. I have a very simple yaml file (for testing):

esphome:
  name: sgm-c4

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: "Weyland Yutani"
  password: "########"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Sml Fallback Hotspot"
    password: "#########"

external_components:
  - source:
      type: local
      path: components
    components: [ sml ]

captive_portal:

web_server:
  version: 2

uart:
  id: uart_bus
  rx_pin: GPIO23
  baud_rate: 9600
  data_bits: 8
  parity: NONE
  stop_bits: 1
  #debug:

sensor:
  - platform: sml
    name: "Total energy"
    obis_code: "1-0:1.8.0*255"
    unit_of_measurement: kWh
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    filters:
      - multiply: 0.0001

The SML in ESPHome also does not work and now you are my last hope ;)

best Nihil

the78mole commented 1 year ago

Hi Nihil,

since I switched from my own optical reader to Tibber Pulse, unfortunately I can not test it. This component didn't change since January. So my questions would be:

This could help to trace down the changes in ESPhome or this component...

PS: I found the OBIS Code also in the SML debug: 01:00:01:08:00:FF, so the input to the SML component seems OK.

Regards, Daniel

NihilUnum commented 1 year ago

Hi Daniel Thanks for such fast respond! I am very new in this area, it is my first attempt, I got already the ESPHome 2023.5.5 version. I got output one time and this was one week ago. Unfortunately it was only a test and I wanted configure my yaml file right. And that was where my misery started. Here is my compile log from today:

docker run --rm --privileged -v "${PWD}":/config -it esphome/esphome run sgm-c4_sml.yaml
INFO ESPHome 2023.5.5
INFO Reading configuration sgm-c4_sml.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing sgm-c4 (board: esp32dev; framework: arduino; platform: platformio/espressif32@5.3.0)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 1.2.2
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 2.1.0
|   |-- AsyncTCP-esphome @ 1.2.2
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- ArduinoJson @ 6.18.5
Compiling .pioenvs/sgm-c4/src/esphome/components/api/api_connection.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/api_frame_helper.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/api_pb2.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/api_pb2_service.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/api_server.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/list_entities.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/proto.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/subscribe_state.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/api/user_services.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/captive_portal/captive_portal.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/esp32/gpio.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/esp32/preferences.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/json/json_util.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/logger/logger.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/md5/md5.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/mdns/mdns_component.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/mdns/mdns_esp32.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/mdns/mdns_esp8266.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/mdns/mdns_host.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/mdns/mdns_rp2040.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/network/util.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/ota/ota_backend_arduino_esp32.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/ota/ota_backend_arduino_esp8266.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/ota/ota_backend_arduino_rp2040.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/ota/ota_backend_esp_idf.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/ota/ota_component.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/sensor/automation.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/sensor/filter.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/sensor/sensor.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/sml/sensor/sml_sensor.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/sml/sml.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/socket/bsd_sockets_impl.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/socket/lwip_raw_tcp_impl.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/socket/socket.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/uart/uart.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/uart/uart_component.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/uart/uart_component_esp32_arduino.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/uart/uart_component_esp8266.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/uart/uart_component_esp_idf.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/uart/uart_component_rp2040.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/uart/uart_debugger.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/web_server/list_entities.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/web_server/web_server.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/web_server_base/web_server_base.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/wifi/wifi_component.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/wifi/wifi_component_esp32_arduino.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/wifi/wifi_component_esp8266.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/wifi/wifi_component_esp_idf.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/components/wifi/wifi_component_pico_w.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/application.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/component.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/component_iterator.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/controller.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/entity_base.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/helpers.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/log.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/scheduler.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/string_ref.cpp.o
Compiling .pioenvs/sgm-c4/src/esphome/core/util.cpp.o
Compiling .pioenvs/sgm-c4/src/main.cpp.o
Linking .pioenvs/sgm-c4/firmware.elf
RAM:   [=         ]  12.4% (used 40548 bytes from 327680 bytes)
Flash: [=====     ]  46.9% (used 860429 bytes from 1835008 bytes)
Building .pioenvs/sgm-c4/firmware.bin
Creating esp32 image...
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/sgm-c4/firmware.bin"], [".pioenvs/sgm-c4/firmware.elf"])
Wrote 0xe37a0 bytes to file /config/.esphome/build/sgm-c4/.pioenvs/sgm-c4/firmware-factory.bin, ready to flash to offset 0x0
======================================================================= [SUCCESS] Took 25.83 seconds =======================================================================

*****************************************************************************************************************************************************************************
We found 1.03GB of unnecessary PlatformIO system data (temporary files, unnecessary packages, etc.).
Use `pio system prune --dry-run` to list them or `pio system prune` to save disk space.
INFO Successfully compiled program.
Found multiple options, please choose one:
  [1] /dev/ttyUSB0 (Sonoff Zigbee 3.0 USB Dongle Plus - Sonoff Zigbee 3.0 USB Dongle Plus)
  [2] Over The Air (sgm-c4.local)
(number): 2
INFO Resolving IP address of sgm-c4.local
INFO  -> 192.168.11.247
INFO Uploading .esphome/build/sgm-c4/.pioenvs/sgm-c4/firmware.bin (866208 bytes)
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from sgm-c4.local using esphome API
INFO Successfully connected to sgm-c4.local
[20:27:14][I][app:102]: ESPHome version 2023.5.5 compiled on Jun 22 2023, 20:24:34
[20:27:14][C][wifi:505]: WiFi:
[20:27:14][C][wifi:363]:   Local MAC: 94:E6:86:09:FF:FF
[20:27:14][C][wifi:364]:   SSID: 'Weyland Yutani'
[20:27:15][C][wifi:365]:   IP Address: 192.168.11.247
[20:27:15][C][wifi:367]:   BSSID: 00:A0:F9:45:FF:FF
[20:27:15][C][wifi:368]:   Hostname: 'sgm-c4'
[20:27:15][C][wifi:370]:   Signal strength: -65 dB ▂▄▆█
[20:27:15][C][wifi:374]:   Channel: 10
[20:27:15][C][wifi:375]:   Subnet: 255.255.255.0
[20:27:15][C][wifi:376]:   Gateway: 192.168.11.254
[20:27:15][C][wifi:377]:   DNS1: 192.168.11.254
[20:27:15][C][wifi:378]:   DNS2: 0.0.0.0
[20:27:15][C][logger:301]: Logger:
[20:27:15][C][logger:302]:   Level: DEBUG
[20:27:15][C][logger:303]:   Log Baud Rate: 115200
[20:27:15][C][logger:305]:   Hardware UART: UART0
[20:27:15][C][uart.arduino_esp32:124]: UART Bus 1:
[20:27:15][C][uart.arduino_esp32:126]:   RX Pin: GPIO23
[20:27:15][C][uart.arduino_esp32:128]:   RX Buffer Size: 256
[20:27:15][C][uart.arduino_esp32:130]:   Baud Rate: 9600 baud
[20:27:15][C][uart.arduino_esp32:131]:   Data Bits: 8
[20:27:15][C][uart.arduino_esp32:132]:   Parity: NONE
[20:27:15][C][uart.arduino_esp32:133]:   Stop bits: 1
[20:27:15][C][sml_sensor:033]: SML 'Total energy'
[20:27:15][C][sml_sensor:033]:   Device Class: 'energy'
[20:27:15][C][sml_sensor:033]:   State Class: 'total_increasing'
[20:27:15][C][sml_sensor:033]:   Unit of Measurement: 'kWh'
[20:27:15][C][sml_sensor:033]:   Accuracy Decimals: 1
[20:27:15][C][sml_sensor:037]:   OBIS Code: 1-0:1.8.0*255
[20:27:15][C][sml:091]: SML:
[20:27:15][C][captive_portal:088]: Captive Portal:
[20:27:15][C][web_server:151]: Web Server:
[20:27:15][C][web_server:152]:   Address: sgm-c4.local:80
[20:27:15][C][mdns:108]: mDNS:
[20:27:15][C][mdns:109]:   Hostname: sgm-c4
[20:27:15][C][ota:093]: Over-The-Air Updates:
[20:27:15][C][ota:094]:   Address: sgm-c4.local:3232
[20:27:15][C][api:138]: API Server:
[20:27:15][C][api:139]:   Address: sgm-c4.local:6053
[20:27:15][C][api:143]:   Using noise encryption: NO
[20:32:03][I][ota:113]: Boot seems successful, resetting boot loop counter.
[20:32:04][D][esp32.preferences:114]: Saving 1 preferences to flash...
[20:32:04][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

Thanks for looking into

best Nihil

the78mole commented 1 year ago

Hi Nihil,

I just remembered, that SML component is already included in ESPhome itself, maybe you should give it a try... https://esphome.io/components/sml.html?highlight=sml

I believe, it is tested way closer and following changes to ESPhome itself more quickly.

Could also be, that ESPhome SML and this SML component are conflicting somehow.

Regards, Daniel

NihilUnum commented 1 year ago

Hi Daniel Just ESPHome was my first attempt, I also created a issue there (https://github.com/esphome/issues/issues/4584) but I got no respond. So I looked for solution and found this thread (https://github.com/esphome/feature-requests/issues/1041#issuecomment-1379847580). I tested yours SML version and from BMOD89. And it looks like I am not the only one with this problem. I tried to solve this by my self but I only know python, not C++. I did not figured how the parser works.

best Nihil

the78mole commented 1 year ago

Hi Nihil,

for parsing, SML is a real pain, because it has recursive lists. I have a Tibber Pulse and the Tibber bridge. I "hacked" the bridge to access the SML message through HTTP. Here you can find my current progress: https://the78mole.de/doing-the-undone-decoding-sml-or-hacking-the-tibber-raw-data/

The blog post is not yet complete, but maybe it helps you a bit to understand that stuff and check the SML message.

Regards, Daniel

NihilUnum commented 1 year ago

Hi Daniel

I will do this, thanks for you time.

best Nihil