Help parsing entity


I just added a tasmota with SDM630 to my Home Assistant:

The mqtt integration recognized the entities:

Now my problem is that for example power is an array of 3 values:

I would like to be able to deal with them separately. I kind of understood I should use templating to be able to create an entity for each of those values

I tried based on examples:

  - platform: template
        friendly_name: "Main Power L1"
        unit_of_measurement: 'W'
        value_template: "{{ state_attr('sensor.main_power_energy_power, '0') }}" 

But this does not work.

Thank you

As far as I understand your sensor, the three numbers are the state of your sensor and not an attribute…
Do you have a view of the state/attributes of your entity ? Like these examples:

Salut Browetd,

Hmm, I cannot see this view, where can you get this in Home Assistant?

It is in “development tools”, “States”… You have there the list of all your entities …


Here we go…

  - platform: template
        friendly_name: "Main Power L1"
        unit_of_measurement: 'W'
        value_template: "{{ states('sensor.main_power_energy_power').split(',')[0] }}"


Thank you, I replace the definition in the config file.

It seems there is still something incorrect.


If the code is in the file “sensors.yaml”, than the first line (sensor) must be removed…
Can you give me the error code in home-assistant.log if the error persists…

I added it to the configuration.yaml.

The error from the log is:

2020-03-25 11:50:53 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.template]: invalid slug main_power_L1 (try main_power_l1) for dictionary value @ data['sensors']. Got OrderedDict([('main_power_L1', OrderedDict([('value_template', "{{ states('sensor.main_power_energy_power').split(';')[0] }}")]))]). (See /config/configuration.yaml, line 35). Please check the docs at

you have an uppercase in the name of the sensor… replace L1 by l1

In the future, please add images directly within the post (like you did in your latest posts) instead of some photo-sharing site with advertising, trackers, etc (like you did in your first few posts).

We want to help you but shouldn’t have to visit dubious sites we would normally not use. Thank you for your understanding.

Yes - did not knew at first, it was so easy to add a picture at first :slight_smile:


The split did not help : s

As an experiment, try this:

value_template: "{{ (states('sensor.main_power_energy_power'))[0] }}"

The fastest way to test it is to use Developer Tools > Template. Paste the following into the Template Editor and see what value it reports:

{{ (states('sensor.main_power_energy_power'))[0] }}

Can you share with us how the sensor main_power_energe_power was created because I created one in my environment with 3 values but it is surrounded by () and not []… and the code I gave you is working in my environment…

The sensor is a Tasmota Wemos D1 reading value from a SDM630 power meter, then sent via MQTT.

It returns values like this unfortunately []

Your expression almost works (just small issue with “[” and “]” on the first and last:

Thank you Didier and Taras, you really help me a lot.

I got it working :slight_smile:

  - platform: template
        friendly_name: "Main L1 Power"
        unit_of_measurement: 'W'
        value_template: "{{ states('sensor.main_power_energy_power').split(',')[0].strip('[') |int}}"
        friendly_name: "Main L2 Power"
        unit_of_measurement: 'W'
        value_template: "{{ states('sensor.main_power_energy_power').split(',')[1] |int}}"

        friendly_name: "Main L3 Power"
        unit_of_measurement: 'W'
        value_template: "{{ states('sensor.main_power_energy_power').split(',')[2].strip(']') |int}}"
        friendly_name: "Main Total Power"
        unit_of_measurement: 'W'
        value_template: "{{ states('sensor.mainpowerl1')|int + states('sensor.mainpowerl2')|int + states('sensor.mainpowerl3')|int}}"

Respectfully, that’s a clumsy way of extracting the values. It may work but I would not promote it as a “Solution” (i.e. users should avoid using this technique).

Happy it is working… as @123 is mentioning, it would have been better to get those values directly from MQTT … By the way to remove the first and the last character, you can also just replace [0] by [0][1:] and to drop the last character [2] by [2][:-1]