pvklink
(peter van Klink)
August 21, 2023, 10:15am
1
Hi,
Is it possible to use a friendly name of a triggering device in a automation, like one of the entitied described in trigger and use this in the action (see xxx)
alias: auto_spraak
description: ""
trigger:
- platform: state
entity_id:
- switch.ac_1b11552_1
- switch.ac_1b11552_2
- switch.ac_1b11552_3
- switch.ac_1b11552_8
- switch.ac_1b11552_10
- switch.ac_1b11552_11
to: "on"
condition: []
action:
- service: tts.google_translate_say
data:
entity_id: media_player.chromecast_huiskamer_nest
message: hallo, irrigatie xxx start
cache: true
language: nl
mode: single
tom_l
August 21, 2023, 10:23am
2
message: "hallo, irrigatie {{ trigger.to_state.name }} start"
1 Like
pvklink
(peter van Klink)
August 21, 2023, 12:28pm
3
Yes! that works great!
Can i also combine this with another condition?
I tried to delete the “to on” in the trigger and add a condition in the choose part, but i cant use the used event-entity id there…
alias: auto_spraak
description: ""
trigger:
- platform: state
entity_id:
- switch.ac_1b11552_1
- switch.ac_1b11552_2
- switch.ac_1b11552_3
- switch.ac_1b11552_8
- switch.ac_1b11552_10
- switch.ac_1b11552_11
to: "on"
condition: []
action:
- choose:
- conditions: []
sequence:
- service: tts.google_translate_say
data:
entity_id: media_player.chromecast_huiskamer_nest
message: hallo, {{ trigger.to_state.name }} start
cache: true
language: nl
mode: single
pvklink
(peter van Klink)
August 21, 2023, 12:30pm
4
Yes! that works great!
Can i also combine this with another condition?
I tried to delete the “to on” in the trigger and add a condition in the choose part, but i cant use the used event-entity id there…
alias: auto_spraak
description: ""
trigger:
- platform: state
entity_id:
- switch.ac_1b11552_1
- switch.ac_1b11552_2
- switch.ac_1b11552_3
- switch.ac_1b11552_8
- switch.ac_1b11552_10
- switch.ac_1b11552_11
to: "on"
condition: []
action:
- choose:
- conditions: []
sequence:
- service: tts.google_translate_say
data:
entity_id: media_player.chromecast_huiskamer_nest
message: hallo, {{ trigger.to_state.name }} start
cache: true
language: nl
mode: single
pvklink
(peter van Klink)
August 21, 2023, 12:42pm
5
I tried this for the conditions block, but no luck
- conditions:
- condition: template
value_template: state.trigger.entity_id = "on"
tom_l
August 21, 2023, 12:45pm
6
What are you trying to do by deleting the trigger state?
If you want a message when they turn both on and off do this:
alias: auto_spraak
description: ""
trigger:
- platform: state
entity_id:
- switch.ac_1b11552_1
- switch.ac_1b11552_2
- switch.ac_1b11552_3
- switch.ac_1b11552_8
- switch.ac_1b11552_10
- switch.ac_1b11552_11
to:
condition: []
action:
- service: tts.google_translate_say
data:
entity_id: media_player.chromecast_huiskamer_nest
message: "hallo, irrigatie {{ trigger.to_state.name }} changed to {{ trigger.to_state.state }}"
cache: true
language: nl
mode: single
pvklink
(peter van Klink)
August 21, 2023, 1:15pm
7
Only thing i wanted is
have one automation for on and off
the message for on for the actual event is
hallo name of the eventid starts
the message for off for the actual event
hallo name of the eventid stops
After your first responce, the on part worked well for all entities…
pvklink
(peter van Klink)
August 21, 2023, 1:20pm
8
Now understand your solution, do not have to chekc the state at all!
it is all in the message
pvklink
(peter van Klink)
August 21, 2023, 1:29pm
9
Thanks for the solution!
Pure for my interest, is it possible to check for the on or off state of the current event in a choose / condition part?
tom_l
August 21, 2023, 1:41pm
10
Sure,
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state = 'on' }}"
pvklink
(peter van Klink)
August 22, 2023, 8:01pm
11
cant get the last part working, checking a trigger state in a choice construct
I know, solution is already there, but this is just to learn
alias: auto_spraak
description: ""
trigger:
- platform: state
entity_id:
- switch.ac_1b11552_1
- switch.ac_1b11552_2
- switch.ac_1b11552_3
- switch.ac_1b11552_8
- switch.ac_1b11552_10
- switch.ac_1b11552_11
condition: []
action:
- choose:
- conditions:
- condition: template
#trial_1: value_template: trigger.to_state.state = "on"
#trial_2: value_template: "{{ trigger.to_state.state = 'on' }}"
#trial_3: value_template: trigger.to_state.state = "on"
value_template: "{{ trigger.to_state.state = "on" }}"
sequence:
- service: tts.google_translate_say
data:
entity_id: media_player.chromecast_huiskamer_nest
message: >-
hallo, {{ trigger.to_state.name }} is {{ trigger.to_state.state
}}
cache: true
language: nl
mode: single
tom_l
August 22, 2023, 8:16pm
12
That one should have worked. How are you testing it?
Manually triggering the automation skips the trigger, so there is no trigger.to_state.
pvklink
(peter van Klink)
August 24, 2023, 10:41am
13
by activating one of the irrigations, other words: one of the trigger entities
pvklink
(peter van Klink)
August 24, 2023, 1:20pm
14
Grr, see that i get an error when using the right syntax you send
Message malformed: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘=’) for dictionary value @ data[‘action’][0][‘choose’][0][‘conditions’][0][‘value_template’]
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state = 'on' }}"
sequence:
- service: tts.google_translate_say
data:
entity_id: media_player.chromecast_huiskamer_nest
message: >-
hallo, {{ trigger.to_state.name }} is {{ trigger.to_state.state
}}
cache: true
language: nl
mode: single
pvklink
(peter van Klink)
August 24, 2023, 1:46pm
15
found it !
must use a double == sign !
value_template: "{{ trigger.to_state.state == 'on' }}"
1 Like
pvklink
(peter van Klink)
August 24, 2023, 1:53pm
16
Thanks tom_l you helped and learned me a lot. My irrigation system works great and speaks when each zone goes on or off…
tom_l
August 24, 2023, 4:33pm
17
Well that was a rookie mistake on my part. Sorry. Glad you worked it out.