Help with "value_template"

Hi guys,

I have tried out all the other posts and solutions I could find but could not solve this simple thing so far :sweat_smile:. I have a SDM630 energy meter which is delivering its data to a Modbus Gateway, which publishes the data via mqtt.

SDM630 β†’ RS485 β†’ Modbus Gateway β†’ Wifi β†’ mqtt broker on Home Assistance.

Unfortunately the Modbus gateway sends the values together with the unit via mqtt.

My configuration file look like this:

sensor:
  - name: sdm630_spannung_L1
    state_topic: Gateway/SDM630/Spannung_L1-N
    device_class: energy
  - name: sdm630_wirkenergie_bezug
    state_topic: Gateway/SDM630/Wirkenergie_Bezug
    state_class: total_increasing
    device_class: energy
  - name: sdm630_gesamtleistung
    state_topic: Gateway/SDM630/Gesamt_Leistung
    device_class: energy

Here how the data look like:

As the unit is already in the values I can’t use the unit field properly. My actual issue is that the Energy dashboard refuses to show the consumption, saying that the value cannot be parsed as number:

Entity has non-numeric state
The following entities have a state that cannot be parsed as a number:
sensor.sdm630_wirkenergie_bezug (1.68kWh)

I tried tons of different variants using the value_template to try to strip the unit from the value, but none worked. Hope someone has a clue what to enter in value_template to strip the V, kWh and W from the sensor values getting the bare values as a result.

Thanks in advance for your support :slight_smile:

sensor:
  - name: sdm630_spannung_L1
    state_topic: Gateway/SDM630/Spannung_L1-N
    device_class: voltage
    state_class: measurement 
    value_template: "{{ value|replace('V', '') }}"
    unit_of_measurement: V
  - name: sdm630_wirkenergie_bezug
    state_topic: Gateway/SDM630/Wirkenergie_Bezug
    state_class: total_increasing
    device_class: energy
    state_class: total_increasing
    value_template: "{{ value|replace('kWh', '') }}"
    unit_of_measurement: kWh
  - name: sdm630_gesamtleistung
    state_topic: Gateway/SDM630/Gesamt_Leistung
    device_class: power
    state_class: measurement
    value_template: "{{ value|replace('W', '') }}"
    unit_of_measurement: W
1 Like

Dear @tom_l ,

thank you soooo much. I get tears of gratitude in my eyes after hours of suffering :joy:
It worked:
image
And the energy dashboard also have no complains.

Cheers^^

1 Like