I am writing a simple automation that is supposed to keep two Switches in sync provided that a certain boolean helper flag is on. I am trying to embed simple jinja logic in the action to achieve this - similar to some examples I found in the Actions documentation, and I tested the code to work in Developer tools actions. I got the automation to work but some behaviour in the YAML editor appears strange to me.
Here is the code:
alias: Bar Audio Switch sync to Entertain
description: ""
triggers:
- trigger: state
entity_id:
- switch.omnilink_bar
conditions:
- condition: state
entity_id: input_boolean.sync_bar_and_entertain_audio
state:
- "on"
- condition: template
value_template: "{{ states('switch.omnilink_entertain') != trigger.to_state.state }}"
actions:
- action: >
{% if trigger.to_state.state == 'on' %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
entity_id: switch.omnilink_entertain
mode: single
Iām not sure how the forum parser will display this, but to be safe here is a screenshot of the last block in the HA yaml interface, where you can see the entity_id color is confused with the preceding multiline jinja block.
Confusingly, if I save and reopen this automation then HA changes my folded style > to a literal | ā why does it do that, is that just part of how it works?
Anyway, just checking whether Iām not doing anything wrong. Any comments on whether the code should be improved would also be appreciated.
