alex3025
(Matteo D.)
December 18, 2024, 6:57pm
1
Why something like this doesn’t work?
trigger: state
entity_id:
- schedule.christmas_lights_schedule
id: "{{ states('schedule.christmas_lights_schedule') }}"
The result is "{{ states('schedule.christmas_lights_schedule') }}"
while I’m expeting on
or off
.
Can’t see anything in the docs about using templates in trigger IDs - I suspect they’re just strings.
1 Like
petro
(Petro)
December 18, 2024, 7:07pm
3
Strings only.
@alex3025
You can get the entity_id that triggered from a template, without needing to add a trigger id
trigger.to_state.entity_id
alex3025
(Matteo D.)
December 18, 2024, 7:25pm
4
Oh, sad moment…
So should I use {{ states('trigger.to_state.entity_id') }}
to get the state of the schedule?
petro
(Petro)
December 18, 2024, 7:26pm
5
you have 2 ways,
trigger.to_state.state
or
states(trigger.to_state.entity_id)
alex3025
(Matteo D.)
December 18, 2024, 7:30pm
6
So I could do something like this? (as automation condition)
condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
petro
(Petro)
December 18, 2024, 7:31pm
7
sure, but why are you doing that? You can just explicitly say that in the trigger.
trigger: state
entity_id:
- schedule.christmas_lights_schedule
to: 'on'
alex3025
(Matteo D.)
December 18, 2024, 7:32pm
8
I want to use a single schedule trigger to trigger on and off statuses
triggers:
- trigger: state
entity_id:
- schedule.christmas_lights_schedule
conditions: []
actions:
- choose:
- conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
sequence:
- type: turn_on
device_id: 610aa9a1e720ddf89d6a4d3c11341317
entity_id: d99fcc55ff51d75e397bc330299eeefc
domain: switch
enabled: true
mode: restart
petro
(Petro)
December 18, 2024, 7:35pm
9
what’s the off going to look like?
123
(Taras)
December 18, 2024, 8:24pm
10
alias: example
description: Turn christmas lights on and off as per schedule
triggers:
- trigger: state
entity_id:
- schedule.christmas_lights_schedule
conditions: []
actions:
- action: "switch.turn_{{ trigger.to_state.state }}"
target:
entity_id: switch.your_switch
mode: single
1 Like