I am building an automation that monitors for scene changes in a specific room (based on the name of the scene). This is what I have so far (the current action is just for debugging purposes):
- id: "1634934515108"
alias: Set Helper - Record Last Living Room Scene
description: ""
trigger:
- platform: event
event_type: call_service
event_data:
domain: scene
service: turn_on
condition:
- condition: template
value_template: "{{'living_room' in trigger.event.data.service_data.entity_id|join}}"
action:
- service: notify.persistent_notification
data:
message: "1 {{trigger.event.data.service_data.entity_id}} 2 {{trigger.event.data.service_data.entity_id|select('search','living_room')|list|join}} 3 {{'living_room' in trigger.event.data.service_data.entity_id|join}}"
mode: single
The trigger and condition are working as intended, running whenever a “living_room” scene is activated. The next step I need to do is parse trigger.event.data.service_data.entity_id
such that I can pass the scene name to an input_select helper to store it. The challange I am having is that trigger.event.data.service_data.entity_id
could evaluate to any of the following 3 formats depending on how a scene is called (based on looking at the logs, not clear why this is happening, see further below):
A 'scene.living_room_warm'
B ['scene.living_room_warm']
C ['scene.living_room_warm', 'scene.bedroom_warm']
I am trying to build a filter to do this. My desired output would look the same as case A, but for any of the 3 cases. I have tried to use the following filter:
{{trigger.event.data.service_data.entity_id|select('search','living_room')|list|join}}
Output:
A
B scene.living_room_warm
C scene.living_room_warm
As you can see, this filter works for case B and C, but not for A. Can anyone provide guidance on how to proceed? Thanks.
As an aside, I do not really understand what causes case A vs B. I know that case A occurs when the entity_id in the event log is formatted like this:
event_type: call_service
data:
domain: scene
service: turn_on
service_data:
entity_id: scene.living_room_neutral
And that case B occurs when the entity_id in the event log is formatted like this:
event_type: call_service
data:
domain: scene
service: turn_on
service_data:
entity_id:
- scene.living_room_neutral
But I don’t really understand when or how or why one vs the other occurs, or how they should be used or treated differently. Is one format legacy? Is one format default from the UI editor? Clearly the way the data can be manipulated is different. Any clarity here or a pointer to the relevent documentation would be greatly appreciated. Cheers.