I am currently working on an automation that triggers based on the state of multiple light entities from the ESPHome integration. My goal is to notify myself whenever any light from the ESPHome integration turns on. Here’s the automation I’ve tried:
However, I am encountering an error: Automation with alias 'Alerta - Teste' failed to setup triggers and has been disabled: Entity {{ states.light | selectattr('entity_id' is neither a valid entity ID nor a valid UUID for dictionary value @ data['entity_id']. Got None
From my understanding, it seems like I cannot use a template in the entity_id field of a state trigger. However, I really need to be able to monitor multiple entities and would like the flexibility of a template for this purpose.
Does anyone have any suggestions on how I can adjust my automation to work as intended? Or is there another approach that could help me achieve my goal? I would really appreciate any help or guidance!
You are correct, templates are not supported in State triggers except in the for key.
You may be able to use a template trigger, but it would be helpful if you could more clearly describe what your goal is. From what you have posted I would start by creating a template sensor:
- alias: Alerta - Test
initial_state: true
trigger:
- platform: state
entity_id: sensor.esphome_lights_on
not_to:
- unavailable
condition:
- "{{ trigger.to_state.state | int > trigger.from_state.state | int }}"
action:
- service: notify.antonio_desktop
data:
title: "Teste"
message: "{{ state_attr(trigger.to_state.attributes.most_recent, 'friendly_name') }} ligou"
Keep in mind that any new light entities coming from ESPHome that you add, but don’t want to be notified about will need to be rejected in your template. In the long run, approaches like this usually end up requiring just as much, or more, maintenance than you will have with a static list of entities in a State trigger.
Hey, thanks for getting back to me, that was super helpful. I’m trying to create a flexible entity_id list (template) that can automatically track some specific devices based on a filter, so I can use the trigger.to_state to get their names in the notify template.