lsobacki
(Łukasz)
December 3, 2024, 10:38pm
1
Hello,
In my push notifications I’m using this template
- condition: template
value_template: >
{{ states.input_boolean.state_push.state == 'on' }}
In need to pass variable defined in script for something like:
- condition: template
value_template: >
{{ states.input_boolean.{{script_variable}}_push.state == 'on' }}
I’ve tried all possible options come to my mind and found everywhere but no luck.
pkscout
(Kyle Johnson)
December 3, 2024, 10:41pm
2
There’s no way that will work using the states.statename.state
format. I think you should be able to do it by joining a set of strings using is_state("statename", "on")
though.
{% set ent = "input_boolean."~script_variable~"_push" %}
{{ is_state(ent, 'on') }}
Though the state object method is not preferred, with it you would use bracket notation:
{{ states.input_boolean[script_variable~'_push'].state == 'on' }}
1 Like
lsobacki
(Łukasz)
December 3, 2024, 11:09pm
4
Thank You So much, I owe You !!!
Actually, both above solutions works.
I’ve figured out my self something simmilar like
{{ states.input_boolean[script_variable~'_push'].state == 'on' }}
but without “~” so details matters !
Code worked like a charm !
Home Assistant is the best automation OS, and have great community !!!
Troon
(Troon)
December 4, 2024, 7:28am
5
Another way to build the string using printf
-style formatting (docs ):
{{ is_state('input_boolean.%s_push' % script_variable, 'on' }}
lsobacki
(Łukasz)
December 4, 2024, 7:45am
6
Thank’s a lot guys, i didn’t expected my issue will bee so interesting.
I appreciate Your help.