I have an automation, that checks if a specific scene has triggered as condition:
automation:
- alias: Alias name
id: UUID
description: 'only start if entity_id contains "scene.clean_" '
trigger:
platform: event
event_type: call_service
event_data:
domain: scene
service: turn_on
condition: >
{{ trigger.event.data.service_data.entity_id.find("scene.clean") | int>=0 }}
action:
This runs without errors. But sometimes, when I start other scenes (not starting with “scene.clean” it throws an error:
Error evaluating condition in 'Alias name': In 'condition': In 'template' condition: UndefinedError: 'list object' has no attribute 'find'
The error led me to investigate the trigger object by listening to the event: “call_service”.
Here, the event->data ->service_data->entity_id
sometimes is a string and sometimes an list object. (in code marked within ** **)
EVENT 1
{
"event_type": "call_service",
"data": {
"domain": "scene",
"service": "turn_on",
"service_data": {
**"entity_id": "scene.clean_floor"**
}
},
"origin": "LOCAL",
"time_fired": "2021-12-21T19:50:51.835697+00:00",
"context": {
"id": "abcdefgh",
"parent_id": null,
"user_id": "0123456789"
}
}
EVENT 2
{
"event_type": "call_service",
"data": {
"domain": "scene",
"service": "turn_on",
"service_data": {
** "entity_id": [
"scene.good_night"
]**
}
},
"origin": "LOCAL",
"time_fired": "2021-12-21T19:19:09.893150+00:00",
"context": {
"id": "abcdefghijklmnopqrstuvwxyz",
"parent_id": null,
"user_id": "0123456789"
}
}
Can someone explain or give a better solution for my automation?
Thank you in advance