volkszaehler / libsml

Implementation in C of the Smart Message Language (SML) protocol
GNU General Public License v3.0
88 stars 49 forks source link

How to use libsml in ESPhome? #146

Closed Qhilm closed 8 months ago

Qhilm commented 8 months ago

Even though ESPhome now has [SML support](# https://github.com/esphome/esphome-docs/blob/current/components/sml.rst), it does not have a specific workaround I need for my WS7412.1.

Hence my question: can I replace this ESPhome yaml (for the ESPHome built-in SML support):

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

with

external_components:
  - source:
      type: git
      url: https://github.com/volkszaehler/libsml
    components: [ sml ]

as a drop in replacement? Or is it more complex than this?

I intend to test this, but I wanted to hear if someone can say I am completely on the wrong track here and it will not work at all like that, I can try to reproduce the workaround either in ESPhome or Home Assistant yaml while using the built-in SML support from ESPHome.

This would be with ESPhome 2023.12.9 and Home Assistant 2024.01.1.

r00t- commented 8 months ago

i am aware that libsml should be usable on esp32, but afaik nobody here does that, and even less using "ESPhome" or "Home Assistant".

they seem to have their own sml implementation: https://github.com/esphome/esphome/blob/dev/esphome/components/sml/sml.cpp

so some more work would be needed to include libsml there.

i suggest you ask at "ESPhome" instead, asking if they can include libsml, or rather you can just look at their code yourself and see if you can adapt it to use libsml internally.

r00t- commented 8 months ago

a web search says that somebody adapted libsml for arduino, which should then build for esp, you could start with that: https://forum.arduino.cc/t/libsml-parsing-smart-meter-language-protocol/1149684

Qhilm commented 8 months ago

I ended up implementing a simplified version of the workaround for the WS7412 power meter that works for me: I'm taking the absolute value of each measurement, without consideration for any serial numbers. A bit raw, but it works for me.

Adapting libsml for ESP32 seems very much overkill considering there is a working sml implementation. I had hopes it was simple, but that was naive from my part I think.