esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

SML Component converts hex value incorrectly to decimal by offset of 256 #5588

Closed Trickfilm400 closed 1 month ago

Trickfilm400 commented 6 months ago

The problem

Hi,

I have a esp with an sml component and the OBIS Code Values in hex format are incorrectly converted to decimal numbers with an offset off 256.

Output of the log of esphome:

[17:23:12][D][sensor:094]: 'Sensor 1.8.0': Sending state 64736.00000 kWh with 2 decimals of accuracy
[17:23:12][D][sensor:094]: 'Sensor 2.8.0': Sending state 6116.00000 kWh with 2 decimals of accuracy
[17:23:12][D][sml:078]: OBIS info:
(...)
[17:23:12][D][sml:084]:   (<server id>) 1-0:1.8.0 [0x000000fde0]
[17:23:12][D][sml:084]:   (<server id>) 1-0:2.8.0 [0x00000018e4]
(...)

The main error: number seems to be converted wrong::

The OBIS Info show a hex number of fde0 which, if entered in a calculator, results in 64992, which is not 64736, which is returned by esphome. 64992 - 64736 = 256 - which is very interesting.

The HEX Number is the correct number which the smart meter also displays, so it doesn't seem to be a reading issue with the sensor.

Another note is the strange behavior: the result in home assistant (so the sensor value of esphome) is for 3/4 days correct, then the value has an offset of -256 for 3/4 days, then after another 3/4 days the value is correct again. After 3/4 days the value gets an offset of +256 which is also for 3/4 days, after which its correct again. This cycle repeats itself.

A reboot / reflash doesn't fix anything.

I have no idea that the hell is going on, this issue started since the beginning. Has anyone experienced something similar already? If I forgot to provide something, just tell me

Maybe similar to this: https://github.com/esphome/issues/issues/4858

Which version of ESPHome has the issue?

ESPHome version 202x.x.x

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.2.x (every version)

What platform are you using?

ESP32

Board

ESP32-WROOM-32 with hichi ttl sensor

Component causing the issue

sml

Example YAML snippet

esphome:
  name: sml
  friendly_name: sml

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

### wifi + ota + encryption + captive portal here ###

uart:
  id: uart_bus
  rx_pin: GPIO4
  baud_rate: 9600
  data_bits: 8
  parity: NONE
  stop_bits: 1
  rx_buffer_size: 2048

sml:
  id: hpz
  uart_id: uart_bus

sensor:
  - platform: sml
    name: "Sensor 1.8.0"
    sml_id: hpz
    server_id: "(<sever id>)"
    obis_code: "1-0:1.8.0"
    unit_of_measurement: kWh
    accuracy_decimals: 2
    device_class: energy
    state_class: total_increasing

Anything in the logs that might be useful for us?

[17:23:12][D][sensor:094]: 'Sensor 1.8.0': Sending state 64736.00000 kWh with 2 decimals of accuracy
[17:23:12][D][sensor:094]: 'Sensor 2.8.0': Sending state 6116.00000 kWh with 2 decimals of accuracy
[17:23:12][D][sml:078]: OBIS info:
(...)
[17:23:12][D][sml:084]:   (xxxx) 1-0:1.8.0 [0x000000fde0]
[17:23:12][D][sml:084]:   (xxxx) 1-0:2.8.0 [0x00000018e4]
(...)

Additional information

No response

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

eNBeWe commented 1 month ago

@Trickfilm400 I had a look at an unrelated bug in sml decoding and stumbled upon an issue with the value handling. Could you maybe have a look if this issue persists with the next release (hoping that my pr is merged in that)?