Hi All! I am trying to use one automation to trigger a script, but I need to pass the entity_id that triggered the automation. Does anyone know where this is found (proper syntax)? I can’t find anything in the docs or on here.
Here is my automation:
- alias: '[HA] Timer X'
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_0, timer.timer_1, timer.timer_2, timer.timer_3, timer.timer_4
condition: []
action:
- service: script.timer_x_execute
data:
timer: trigger.event.data.event.data.entity_id
In the last line I am looking for one of the following to pass into the script: timer.timer_0, timer.timer_1, timer.timer_2, timer.timer_3, timer.timer_4
I have tried:
trigger.event.data.event.data.entity_id
trigger.event.data.entity_id
trigger.event.event_data.entity_id
Any help would be greatly appreciated!
1 Like
123
(Taras)
June 25, 2019, 5:41pm
2
I’ve performed a few experiments and I’ve discovered two things:
This is the correct way to refer to the entity_id
that triggered the automation:
action:
- service: script.timer_x_execute
data_template:
timer: '{{trigger.event.data.entity_id}}'
The information above is useless to you because the automation will fail to trigger if you supply more than one entity_id
.
You can prove it to yourself by eliminating all timers from entity_id:
except for timer.timer_0
. The resulting automation will trigger when timer_0 is finished. Add one more timer to entity_id:
and the automation will fail to trigger when either of the two timers finishes.
Here’s the automation I used for the experiment.
- alias: 'timer x'
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer1
action:
- service: system_log.write
data_template:
message: 'TIMER FINISHED = {{trigger.event.data.entity_id}}'
level: warning
It works with:
entity_id: timer.timer1
or this:
entity_id: timer.timer2
but fails to trigger with this:
entity_id: timer.timer1, timer.timer2
or this:
entity_id:
- timer.timer1
- timer.timer2
2 Likes
@123 You’re a rockstar! Thanks! I did try it without the list or entity_ids, but I still couldn’t get the entity_id data. I needed to use a data_template
and use the {{}}
Thanks this is working now!
- alias: '[HA] Timer X'
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_0
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_1
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_2
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_3
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_4
condition: []
action:
- service: script.timer_x_execute
data_template:
timer: '{{trigger.event.data.entity_id}}'
A bit of a shame that a list of entities doesn’t work, but this is the next best thing.
4 Likes
KSC
June 10, 2020, 7:13pm
4
Thanks for this, @gremblin and @123 ! I know it’s a little dated, but it’s exactly what I was looking for!! ANd I do agree - not sure why you can’t add a list of entities, but I’m okay with the work-around of using a list of trigger events like you did, @gremblin .
1 Like
tinuva
(David)
March 1, 2021, 4:23pm
5
We in 2021 and still this solution work, no can do on list of event_ids for timers that finished
1 Like
sekt1953
(Svenn-Erik K. Thomsen)
March 6, 2021, 8:08pm
6
I think I have a simpler way
Automation: Timer X
alias: Timer X
description: ''
trigger:
- platform: event
event_type: timer.finished
condition: []
action:
- service: script.timer_x_execute
data_template:
message: '{{trigger.event.data.entity_id}}'
mode: parallel
max: 10
Script: timer_x_execute
alias: timer_x_execute
sequence:
- service: notify.notify
data:
title: 'Time Out'
message: '{{ message }}'
mode: parallel
icon: 'hassio:timer-sand'
max: 10
sekt1953
(Svenn-Erik K. Thomsen)
October 14, 2021, 5:45pm
7
Here is my version, I have a lot of timer i used for cooking, baking, and cooking eggs
alias: timer2 twat
description: ''
trigger:
- platform: event
event_type: timer.finished
event_data: {}
condition: []
action:
- service: persistent_notification.create
data:
message: >-
{{ trigger.event.data.entity_id |
replace("timer.fodselsdagsboller_bagetid", "Fødselsdagsboller bagetid
slut") | replace("timer.fodselsdagsboller_haevetid_2",
"Fødselsdagsboller hævetid 2 slut") }}
mode: parallel
max: 10
123
(Taras)
October 14, 2021, 6:53pm
8
Just for fun, try this version. It uses the timer’s friendly_name
.
alias: timer2 twat
description: ''
trigger:
- platform: event
event_type: timer.finished
event_data: {}
condition: []
action:
- service: persistent_notification.create
data:
message: "{{ state_attr(trigger.event.data.entity_id, 'friendly_name') }} slut"
mode: parallel
max: 10
sekt1953
(Svenn-Erik K. Thomsen)
October 15, 2021, 7:53am
9
Thanks, that’s a really good idea
sekt1953
(Svenn-Erik K. Thomsen)
October 17, 2021, 9:50pm
10
Hi
I think I have found a way without creating event in the trigger part
I create a group in file: /config/groups.yaml with all my hours that I use in my kitchen.
goes in Configuration validation
restarts if the file was ok
creates an automation
/config/groups.yaml
kitchen_timers:
name: Kitchen Timers
entities:
- timer.aeg_blodkogte
- timer.aeg_hardkogte
- timer.fodselsdagsboller_haevetid_1
- timer.fodselsdagsboller_haevetid_2
- timer.fodselsdagsboller_bagetid
- timer.morgen_bollere_bagetid
- timer.rugbrod_haevetid
- timer.rugbrod_bagetid
- timer.svendbrodet_haevetid_1
- timer.svendbrodet_haevetid_2
- timer.svendbrodet_bagetid
- timer.svendboller
- timer.grahamsbrod_haevetid
- timer.grahamsbrod_bagetid
Automation:
alias: 03_Device updated
description: ''
trigger:
- platform: event
event_type: timer.finished
condition:
- condition: template
value_template: >-
{{ trigger.event.data.entity_id in (expand('group.kitchen_timers') |
map(attribute='entity_id')) }}
action:
- service: persistent_notification.create
data_template:
title: 'Timer Slut !! '
message: '{{ state_attr(trigger.event.data.entity_id, ''friendly_name'')}}'
mode: single
sekt1953
(Svenn-Erik K. Thomsen)
October 17, 2021, 9:52pm
11
I based my work on this link:
fwiw, you can also use:
{% set num_lights = expand('group.indoor_light_summary')| count %}
that is, I’ve tested that with the automatic group
{% set num_lights = expand(‘group.all_lights’)| count %}
123
(Taras)
October 18, 2021, 3:16am
12
Here’s an alternative that uses a State Trigger.
alias: timer test
trigger:
- platform: state
entity_id:
- timer.aeg_blodkogte
- timer.aeg_hardkogte
- timer.fodselsdagsboller_haevetid_1
- timer.fodselsdagsboller_haevetid_2
- timer.fodselsdagsboller_bagetid
- timer.morgen_bollere_bagetid
- timer.rugbrod_haevetid
- timer.rugbrod_bagetid
- timer.svendbrodet_haevetid_1
- timer.svendbrodet_haevetid_2
- timer.svendbrodet_bagetid
- timer.svendboller
- timer.grahamsbrod_haevetid
- timer.grahamsbrod_bagetid
from: active
to: idle
condition: []
action:
- service: notify.persistent_notification
data:
title: 'Timer Slut !! '
message: '{{ trigger.to_state.name }}'
mode: single
sekt1953
(Svenn-Erik K. Thomsen)
October 18, 2021, 5:41am
13
Hi Taras
is not what is described in the beginning as not working, I will test your idea, but has there come a correction for timer functionen that allow this.
123
(Taras)
October 18, 2021, 12:46pm
14
sekt1953:
I will test your idea
I encourage you to test it. I tried it with a State Trigger containing three timers and it reported which one changed its state from active
to idle
.
sekt1953
(Svenn-Erik K. Thomsen)
October 18, 2021, 1:02pm
15
I have testet your idea, and it works !!!
I have det timers shown in my lovelace UI, haw can I make den respond to a click and call a service that start the timer, not having to open a new dialog.
Now the timer open a new dialog and I press start.
Svenn-Erik
sekt1953
(Svenn-Erik K. Thomsen)
October 18, 2021, 1:04pm
16
here is my lovelace card:
Æg- & Bage-timer:
type: grid
cards:
- type: entities
entities:
- entity: timer.aeg_blodkogte
- entity: timer.aeg_hardkogte
state_color: true
title: Æg
show_header_toggle: false
- type: entities
entities:
- entity: timer.rugbrod_haevetid
name: Hævetid
- entity: timer.rugbrod_bagetid
name: Bagetid 170 °C
title: Rugbrød
state_color: true
- type: entities
entities:
- entity: timer.fodselsdagsboller_haevetid_1
name: 1. Hævetid
- entity: timer.fodselsdagsboller_haevetid_2
name: 2. Hævetid
- entity: timer.fodselsdagsboller_bagetid
name: Bagetid 200 °C
title: Fødelsdagsboller
state_color: true
- type: entities
entities:
- entity: timer.svendbrodet_haevetid_1
name: Hævetid 1
- entity: timer.svendbrodet_haevetid_2
name: Hævetid 2
- entity: timer.svendbrodet_bagetid
name: Bagetid Brød
- entity: timer.svendboller
name: Bagetid Boller
title: Svenn 230 °C
state_color: true
- type: entities
entities:
- entity: timer.morgen_bollere_bagetid
name: Bagetid 225 °C
title: Morgen Boller
state_color: true
- type: entities
entities:
- entity: timer.grahamsbrod_haevetid
name: Hævetid
- entity: timer.grahamsbrod_bagetid
name: Bagetid 200 °C
title: Grahamsbrød
state_color: true
columns: 2
square: false