rossk
July 25, 2022, 4:15pm
1
Hi All
Am I being really stupid here (probably as its been a long day) but for the life of me I cant seem to get this to work, or in fact even confirm it should:
PARTIAL AUTOMATION:
trigger:
- device_id: df9b3ff7a16e7d73a89b3eadbf63b861
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: 850d897b-294c-4ede-b889-b3fa964104ee
id: kitchen
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.{{ trigger_id }}_motion_sensor_motion
I have tried qoutes and no qoutes and constantly get the following results:
Template rendered invalid entity IDs: switch._motion_sensor_motion
What blindingly obvious am I missing here?
PS. I dont normally trigger off of devices but I was just testing and will likely end up using the hue event once I have worked out why I am failing at the first hurdle.
TIA
calisro
(Rob)
July 25, 2022, 4:23pm
2
I believe its ‘trigger.id’. and yes it will work.
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.{{ trigger.id }}_motion_sensor_motion
1 Like
calisro
(Rob)
July 25, 2022, 4:26pm
3
btw, you can really just assign any variables to the trigger as well…
trigger:
- platform: xxxx
xxxx
variables:
some_trigger: value
action:
- service: switch.turn_off
data: {}
target:
entity_id: {{ some_trigger }}
1 Like
rossk
July 25, 2022, 4:27pm
4
Thanks @calisro you were of course right it should have been:
entity_id: switch.{{ 'trigger.id' }}_motion_sensor_motion
Can you do me a favour…just for clarity for others, can you edit your above post yaml to include the ’ ’ and then I can mark it as the solution.
Thanks again mate
calisro
(Rob)
July 25, 2022, 4:30pm
5
You don’t need those quotes. I believe those quotes will make it a literal and make it NOT work as you’d expect.
This is an example from mine.
action:
- service: lock.unlock
data: {}
target:
entity_id: lock.{{trigger.id}}_door
rossk
July 25, 2022, 4:34pm
6
Strange as this logs and error and does not work:
- service: switch.turn_off
data: {}
target:
entity_id: switch.{{ trigger_id }}_motion_sensor_motion
This does not log an error and works:
- service: switch.turn_off
data: {}
target:
entity_id: switch.{{ 'trigger_id' }}_motion_sensor_motion
calisro
(Rob)
July 25, 2022, 4:36pm
7
Put this in the developer tab in your home assistant and you will see what it is doing:
entity_id: switch.{{ 'trigger.id' }}_motion_sensor_motion
It will literally make it
entity_id: switch.trigger.id_motion_sensor_motion
calisro
(Rob)
July 25, 2022, 4:37pm
8
How are you testing it? Are you trying to execute it manually? The trigger variable wouldn’t be set if you tried to manually execute it.
calisro
(Rob)
July 25, 2022, 4:38pm
9
This may not log an error but it isn’t ‘turning off’ your intended switch quotes in it.
rossk
July 25, 2022, 4:38pm
10
Your right, I have just checked it and although the automation completes without error in the debug its clearly now calling “switch.trigger_id_motion_sensor_motion”
I am checking it by physically triggering the switch.
calisro
(Rob)
July 25, 2022, 4:39pm
11
Paste your entire automation.
This should be what you need:
trigger:
- device_id: df9b3ff7a16e7d73a89b3eadbf63b861
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: 850d897b-294c-4ede-b889-b3fa964104ee
id: kitchen
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.{{ trigger.id }}_motion_sensor_motion
assuming you want to turn off
switch.kitchen_motion_sensor_motion
rossk
July 25, 2022, 4:42pm
12
alias: testing
description: ''
trigger:
- device_id: eb20d4f24cec0e41a8799f83b1786e09
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: 9473b58b-5684-4456-8668-e7d9ef834301
id: bedroom
- device_id: 8855c1e044222311a2da1c90344cc7ad
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: cf0b67dd-5683-49f9-92b9-8a346c7d64ef
id: bedroom
- device_id: 5f9ef66105117045126056d40361ffd4
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: fddbf3f0-2829-48a9-a7d3-79b13bb00375
id: bedroom
- device_id: 1d7d795402dd6b480d3cc79651517dd4
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: dcd3515d-84f5-4135-abc2-f9c35123e102
id: front_room
- device_id: 9e23fe42623eb447b1b52f90384c1140
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: ad4a0d58-bd18-48fc-b0dd-b7630d8d41b8
id: gemma
- device_id: df9b3ff7a16e7d73a89b3eadbf63b861
domain: hue
platform: device
type: long_release
subtype: 4
unique_id: 850d897b-294c-4ede-b889-b3fa964104ee
id: kitchen
condition: []
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.{{ trigger_id }}_motion_sensor_motion
mode: single
And the error in debug:
Triggered by the event 'hue_event' at 25 July 2022 at 17:39:18
Call service switch.turn_off on templated entities
Stopped because an error was encountered at 25 July 2022 at 17:39:18 (runtime: 0.01 seconds)
Template rendered invalid entity IDs: switch._motion_sensor_motion
calisro
(Rob)
July 25, 2022, 4:45pm
13
But… You still have the wrong thing there. It should be
entity_id: switch.{{ trigger.id }}_motion_sensor_motion
1 Like
rossk
July 25, 2022, 4:49pm
14
Well don’t I feel really stupid now.
Thank you so much for your time on this Rob, I really don’t know how I managed to F that up so badly.
Its all working as expected now
1 Like