Shelly 2.5, tasmota, mqtt split values from sensor

I am using a Shelly 2.5 measure power usage of two devices. The Shelly 2.5 is flashed with Tasmota and connected to Home Assistant with MQTT.

The Shelly 2.5 is automatically detected and added to Home Assistant via MQTT integration. It adds multiple buttons/switches. However it adds just one power sensor that contains two values in an array. So far so good.

However I would like to have the readings in two separate sensors to be more usable. Via value_template I tried to achieve this:

        friendly_name: "Watt MV"
        value_template: "{{ states('sensor.mv_energy_power')[0]}}"

However the sensor becomes ‘[’. As Home Assistant intreprets the sensor reading as string rather than an array. Does anyone know how I can cast it to an array, or achieve the result of two different sensors with their respective values in any other way? Thanks a lot in advance!

My guess:

states('sensor.mv_energy_power') | split("x")[0]
states('sensor.mv_energy_power') | split("x")[1]

Change x to whatever symbol is dividing your array.

Please confirm :slight_smile:

Thnx for your reaction. I tried to test in templates tab (under development tools). If I put it there like:


This results in: Error rendering template: TemplateAssertionError: no filter named ‘split’

I don’t put a parameter to the split filter, as the input (from states(‘sensor.mv_energy_power’)) is [5, 2]. Am overlooking something from your advice? Thnx for your time!

Ok, maybe:


That works partly as it still keeps the ‘[’ and the ‘]’ in the result (as expected on a string split).

Eventually I solved with: states(“sensor.mv_energy_power”)|regex_findall_index("(\d+)", 0)}}, maybe not he most performant way, but for now it’s ok. Thanks for your help!

It works this way:
{{ (states("sensor.mv_energy_power") | from_json)[0] }}
{{ (states("sensor.mv_energy_power") | from_json)[1] }}

Thank you! Great to have a proper solution in place!