I need your help, I use Pellmon to monitoring my Pellet burner in my house, I have connected the Pellmon system via Raspberry pi and MQTT, it sends message to Home Assistant with all the temperatur data and more.
What I need help for is to convert the state message to simple (“On / Off text”) the state of the pellet burner ( is it running or is it stopped) I get this message via MQTT from the Pellmon 2021-12-06 00:29:43,759 - INFO - ‘mode’ changed from ‘Running’ to ‘Stopped’)
How can I specify that I want the home assistant to concentrate only on the text Running and Stopped and translate it to ON / OFF so I can make a sensor out of it and log the state change.
{% set x = "INFO - ‘mode’ changed from ‘Running’ to ‘Stopped’" %}
{% set y = x.split(" to ")[1] %}
{% if y == "‘Stopped’" %}
{{ "off" }}
{% elif y == "‘Running’" %}
{{ "on" }}
{% endif %}
If the message has the trailing parenthesis ) shown in your first post then the template will need to be adjusted slightly.
I assume you intend to use this in an MQTT Binary Sensor (specifically in the value_template option) so that’s why the template employs the value variable.