I am trying to create my own blueprint for a cover day-night-cycle automation. Unfortunately I am having issues with using variables in my blueprint and it’s throwing errors left and right. Here is an example (excerpt):
blueprint:
input:
cover_entity:
name: Cover(s)
description: lorem ipsum
selector:
entity:
filter:
- domain: cover
multiple: true
variables:
cover_entity: !input cover_entity
cover_entities: >
{% set individual_covers = [] %}
{% if cover_entity is string %}
{% set cover_entity = [cover_entity] %}
{% endif %}
{% for entity in cover_entity %}
{% if entity in integration_entities('group') %}
{% for member in entity.attributes.entity_id %}
{% set individual_covers = individual_covers + [member] %}
{% endfor %}
{% else %}
{% set individual_covers = individual_covers + [entity] %}
{% endif %}
{% endfor %}
{{ individual_covers }}
triggers:
- alias: Triggered by Cover State Change
id: cover_state_changed
trigger: state
to: null
entity_id: "{{ cover_entities }}"
Error is: Message malformed: Entity {{cover_entity}} is neither a valid entity ID nor a valid UUID for dictionary value @ data['entity_id']
Other issues (that don’t really matter in this case):
For values to be available to the trigger they must be set in a trigger_variables block.
It might be different for blueprints, but trigger_variables for regular automations only allow Limited Templates, so anything that need to access the state object would not be usable.
You would need to use a namespace to extract the value out of the loop, if you want to do it that way…
{% set individual = namespace(covers=[]) %}
{% for entity in cover_entity %}
{% if entity in integration_entities('group') %}
{% set individual.covers = individual.covers + [state_attr(entity, 'entity_id')] %}
{% else %}
{% set individual.covers = individual.covers + [entity] %}
{% endif %}
{% endfor %}
{{ individual.covers|flatten }}
You can make that template a lot shorter by using expand():
I noticed I made a small mistake in my post (I’ve tried around a lot with different approaches to fix this). The error message was from when I tried to use entity_id: "{{ cover_entity }}" directly, not "{{ cover_entities }}". Other than that, the error message stays the same.
But I would need to use "{{ cover_entities}}", which is why I can’t really work with !input.
Reason behind this:
The blueprint takes an input of one or multiple cover entities. Some of which might be groups.
What I am doing as part of the automation is suspend the automation for specific covers if they have been manually operated (I don’t want them to close again right after they were manually opened just because of some new trigger). I am doing this by writing manual operations to a sensor attribute and whenever there is any state change to any of the covers I add them to that suspension list (of course accounting for the fact that the state change might have been triggered by the automation).
To do this, I’ll need to use this.entity_id in order to add the cover to the suspensions list. But if a group has triggered the automation, then the entire group will be added to the list (because of this.entity_id) instead of just the one cover that has actually had a state change.
Therefore my approach was to expand any groups found in the input and add them as individual triggers.
Does this help to understand what I’m trying to achieve? if not, please let me know!
If the issue that state triggers don’t allow for templates (didn’t know that, thanks for the info!), is there maybe a way to do this with a template trigger?