Hello everyone,
following a nice disccusion with great support by some of the community members, I think I will be working on my coding in Jinja skills.
I am currently trying to get an automation to work but I am a bit stuck.
I am checking status changes of a bunch of entities and I want to adjust the message sent to my telegram/signal account based on the origin.
However, it seems that my code is not yet acceptable because HA won’t even save it when I use the visual editor/yaml editor in “Configuration - Automations”.
....
condition: []
action:
msgorigin = {{ trigger.to_state.attributes.friendly_name }}
msgcontent = {{ trigger.to_state.state }}
{% if 'climate' in msgorigin %}
msgcontent = {{ trigger.to_state.attributes.temperature }}
# {% else %}
# bye
{% endif %}
- service: notify.signal
data_template:
message: msgorigin: msgcontent
- service: notify.telegramgroup
data_template:
message: msgorigin: msgcontent
So, as you can see I wanted to first define a default value for message origin and message content. If I am not mistaken I have to use templating, so {{ }} for this.
Then, if the entity contains “climate”, so climate.livingroom or climate.diningroom etc., I would like to see the temperature value rather than the new state.
Once this is done, I would like to send a message to telegram and signal.
My inital code without the If statement and without defining any default values worked
condition: []
action:
- service: notify.signal
data_template:
message: '{{ trigger.to_state.attributes.friendly_name }}: {{ trigger.to_state.state
}}'
- service: notify.telegramgroup
data_template:
message: '{{ trigger.to_state.attributes.friendly_name }}: {{ trigger.to_state.attributes.temperature
}}'
Could someone tell me what I am doing wrong? I thought I had correctly combined information from Jinja — Jinja Documentation (2.11.x) and other sources.
Thank you once again for your great support for an eager noobie!
Alex