This works with no issues.
If I combine the two inputs into a variable and then use the variable in the condition I get an error of “entity ID is not valid”
Thanks @petro
I’ve made the change and I have checked that I am definitely passing a list of entity ids to the entity_id in the condition, but I am always getting the error:
Entity ID {{ all_light_entities }} is an invalid entity ID for dictionary value @ data['action'][0]['choose'][0]['conditions'][1]['entity_id']. Got None
I have even tried setting a variable to a single entity_id and I get the same error e.g.
Entity ID {{ primary_light_entity }} is an invalid entity ID for dictionary value @ data['action'][0]['choose'][0]['conditions'][1]['entity_id']. Got None
but if I remove the variable and put the entity_id string there it works e.g.
It suggests that variables can be used in triggers from 2021.3 onwards. Do you know if this is only for MQTT triggers? The release notes make it sound like variables can be used in all triggers.
I am trying to provide a list of entity_ids to my state trigger, where the id’s are added as part of the blueprint input, but I just can’t seem to find a way of doing something simple like this:
trigger:
- platform: state
entity_id: "{{ light_entities }}"
Where light_entities is list of entities either as a comma ‘,’ separated string or as a list.
I’m finding this whole area very confusing and the documentation is so vague
I’m not sure what’s vague about it? It’s available exactly how it’s written in what you posted. Put the light_entities list inside the trigger_variables section.
I’m not sure why’d you even bother doing that though, you’re still maintaining a list, so just put the list in the trigger.
I’m not an expert on HA like you and am a relative newbie, so still trying to understand its various features and quirks. The documentation often relies on you being an advanced user to understand it. That’s all I mean.
Regarding the post. I am getting the following error when reloading the automtations and it has me stumped:
2021-06-04 13:32:11 ERROR (MainThread) [homeassistant.components.automation] Blueprint Test generated invalid automation with inputs OrderedDict([('light_target', OrderedDict([('entity_id', ['light.dining_ceiling', 'light.family_ceiling', 'light.hall_ceiling'])]))]): Entity ID {{ light_entities }} is an invalid entity ID for dictionary value @ data['entity_id']. Got None
Are you able to shed any light on what I am doing wrong.
The full blueprint I am using to try an understand the problem is below. Notice the commented out attempts at using different ways to achieve the result I want. Only the entity_id: "light.hall_ceiling, light.dining_ceiling" works for me, but I can’t use this as it is not using the blueprint input.
blueprint:
name: Test
description: |
Put description here
domain: automation
input:
light_target:
name: Lights
description: The light(s) to control
selector:
target:
entity:
domain: light
#
# The automation
#
variables:
lights: !input light_target
light_entities: "{{ lights.entity_id }}"
# light_entities: "{{ lights.entity_id|join(',') }}"
# Trigger mode
mode: single
# Triggers
trigger:
- platform: state
entity_id: input_boolean.test
- platform: state
# entity_id: "light.hall_ceiling, light.dining_ceiling"
entity_id: "{{ light_entities }}"
# Conditions
condition:
- "{{ trigger.entity_id in lights.entity_id }}"
# Actions
action:
- service: notify.mobile_app_kaboom
data:
message: test passed
To put a little more context around the above.
My aim is to listen to HomeKit events and catch state changes to a limited list of lights so that I can turn off occupancy sensors when Siri is asked to turn the light on.
I didn’t want to trigger on every single HomeKit event, so was hoping to be able to set a trigger only for the lights using occupancy sensors.
Petro’s post, the Solution post, explains you cannot use a template for a State Condition’s entity_id. However, the most recent blueprint you posted still contains a templated entity_id option for a State Trigger (equally disallowed):
trigger:
- platform: state
entity_id: input_boolean.test
- platform: state
# entity_id: "light.hall_ceiling, light.dining_ceiling"
entity_id: "{{ light_entities }}"
@petro Interesting. I started with what you suggested:
- platform: state
entity_id: !input light_target
but I get the error:
2021-06-04 14:56:12 ERROR (MainThread) [homeassistant.components.automation] Blueprint Test generated invalid automation with inputs OrderedDict([('light_target', OrderedDict([('entity_id', ['light.dining_ceiling', 'light.family_ceiling', 'light.hall_ceiling', 'light.landing_ceiling'])]))]): Entity ID entity_id is an invalid entity ID for dictionary value @ data['entity_id']. Got None
It only works if I have one entity in the light_target
That’s what started me trying out other methods and led me to the 2021.3 release notes post.
- alias: trigger variables test 1
trigger_variables:
lights: ['light.hallway_light', 'light.bedroom_lamp', 'light.foyer_light']
trigger:
- platform: state
entity_id: '{{ lights }}'
action:
- service: notify.persistent_notification
data:
title: Trigger variable test
message: "{{ trigger.to_state.name }} is {{ trigger.to_state.state }}"
Running Check Configuration generates this:
Logger: homeassistant.config
Source: config.py:443
First occurred: 10:00:28 (1 occurrences)
Last logged: 10:00:28
Invalid config for [automation]: Entity ID {{ lights }} is an invalid entity ID for dictionary value @ data['entity_id']. Got None. (See /config/configuration.yaml, line 9).
I get the same result even if I reduce the trigger_variable to just this:
trigger_variables:
lights: 'light.hallway_light'
It’s unhappy seeing a templated entity_id in a State Trigger.
That’s what I mean about the documentation. For example, as a newbie it is very difficult to find clear information on variables & trigger_variables and where they can/cannot be used. Or even why they are different.
Don’t get me wrong I still think HA is the best solution out there, but it has a very steep learning curve and documentation that assumes you are already on top of the curve.
Yeah my understanding is that trigger_variables can be used only with options that already support templates (in this case, the so-called “limited templates”).
I think you’re thinking to far into this. The docs explain exactly what they are used for, you’re just not used to the docs. trigger_variables are used for triggers that use trigger_variables. I’m not sure what more can be explained. I guess it’s missing “This can only be used with triggers”, however the individual triggers specify that they can use it. This is only listed in Event and MQTT triggers, therefore it can only be used for those triggers.
As for variables, those fields are described in the automation action docs and script docs.
There’s not much to it. It’s a single field, and referenced in both triggers that use it. If you think you can write that section better, by all means, go for it.