MQTT Help with non JSON payload

I need some help with a MQTT sensor that is providing a payload that looks like this “On 100”. The payload references a light switch. I need to be able to parse out the two variables so that I can test the ‘On’ variable and the ‘100’ variable separately in a template. I don’t think this qualifies as JSON since it is not “State:” “On”, “Level” “100”. But I am really new to building automations and I am not completely sure.

Does anyone know how to extract the two variables in a template?

Thanks!

Hi @eHouse, you can play with this in Developer Tools / Templates.

{% set teststring = "On 100" %}
{{ teststring.split(' ')[0] }} # returns On
{{ teststring.split(' ')[1] }} # returns 100
1 Like

Thank you very much for your help! I was able to get it to work as,

{{ states.sensor.desk_lamp.state.split(’ ‘)[0] }}
{{ states.sensor.desk_lamp.state.split(’ ')[1] }}

Perfect…