Use Case:
I have an AVR. When I send it a TTS, it’s going to switch to Input Source ‘PC’ - I want it to go back to what it was.
I’ve tried quite a few different ways, one of the most ‘surefire ways’ was to trigger on ANY change it does and Publish to MQTT. This arose an issue since the change to PC ALSO publishes.
So I did some digging and found {% set %} Py-var works in Jinja. However, like every other method I’ve tried, either breaks config or breaks the compilation.
If someone could assist with proper way to handle templates. Here is a very basic automation, that I am wondering for each.
- alias: "AAATest Turn On Office Lights"
trigger:
- platform: state
entity_id: binary_sensor.office_motion_sensor
to: 'off'
action:
- service: light.turn_off
data_template: '{% set heh = states.group.all_devices.attributes.order %}'
entity_id: light.niflheim
transition: '{{heh}}'
attributes order returns a number - In this case a ‘1’.
I have tried this version about ~10 different ways, using value_template (in the same spot as the current template is) and got similar results. One of the formats I was able to get it to render the number, but only if it was a singular action.
The PRIMARY use case.
- alias: "AAATest Turn On Office Lights"
trigger:
- platform: state
entity_id: binary_sensor.office_motion_sensor
to: 'off'
action:
- service: light.turn_off
data_template: '{% set heh = states.group.all_devices.attributes.light %}'
entity_id: light.'{{heh}}'
transition: '60'
Welcome ANY input or ideas. My next idea is to build my own component or rely heavily on shell scripts. However, I’ve seen questions about variables/state saves asked quite a lot in the chat, and I have no idea how to answer it.
I assume I could maybe leverage
trigger.from_state The previous state object of the entity.
trigger.to_state The new state object that triggered trigger.
MAYBE in the action (I assume they’re held in memory for the sequence?) But it’s attributes I need for each use case.
Welcome -any- input.