daifel
1
In automation I call a script:
service: script.my_script
data:
cover_id: cover.my_cover
How can I access the attributes of cover.my_cover
that is passed as cover_id
to the script? I tried something like this, but it is not working:
condition: template
value_template: '{{ cover_id.attributes.current_position > 50 }}'
condition: template
value_template: '{{ states[cover_id].attributes.current_position > 50 }}'
ih8gates
(Scott Reston)
2
I haven’t tried this, but another idea to try: you can use this type of syntax to refer to it:
{{ states(cover_id) }}
Experiment with the template dev tool.
daifel
3
Thanks, but states(cover_id)
will return only the state string and not the object
I’ve tried already a lot of things and unfortunately no more ideas.
sysop
4
Did you figure it out by now? I think I have a similar problem and there’s no solution in sight…
petro
(Petro)
5
@daifel, @ih8gates, @sysop
should just be {{ cover_id }}. Passing variables spells this out perfectly in the script documentation:
Look at the last example.
From that point forward, if you are trying to get cover attributes, you need to split the domain and device from the cover id:
value_template: >
{% set domain, device = cover_id.split('.') %}
{{ states[domain][device].attributes.current_position > 50 }}
or
value_template: >
{{ state_attr(cover_id, 'current_position') > 50 }}
these methods are covered in:
1 Like