Hello everyone!
Here’s my 1st try to get active help from all your HA experts
I did read hundreds of postings and learned a lot but now I’, stucked…
What I have (or plan to build): a group of input.boolean helper (“Mo”, “Di”, “Mi”, “Do”, “Fr”, “Sa”, “So”) represented as a button on my dashboard.
I’m looking for a nice idea to get “true” or “false” of the corresponding weekday-item by using '{{ now().weekday() }} - or anything else - as an index to access the group (or array).
A ‘brute force’ way would result in endles cascading IF THEN ELSE code.
I hope that my desription could be understood, any hint to an already documented solution would be fine too.
Thank you so much and have a nice day!
Wilfrid
I was looking for a template to check ie the 3rd item in my group - when current weekday is “3” and so on. I succeed with a template that results in a list with all entities with state ‘on’. Unfortunately not helpful for me. My idea was - maybe I’m wrong here - that a group is the same as an array where I can access elements by an index.
So I have to try and error more…
thanks, might be useful for other stuff. I want to tell my automation only to run on dedicates weekdays (as defines by these boolean input helper). But weekday toggles are not used as trigger, only as state.
But maybe I found another solution - and another problem to solve: place a parameter / field value into a template expression of a script. Seems not to be allowed
In the following example, group.days is a legacy Group containing seven Input Booleans. Its entity_id attribute contains an ordered list of seven input_boolean entities (starting with the Input Boolean representing Monday and ending with the one for Sunday).
The second line checks if the state of the input_boolean corresponding to the current day is on.
{% set days = state_attr('group.days', 'entity_id') %}
{{ is_state(days[now().weekday()], 'on') }}
Thanks a lot! That is what I was looking for! Working well and will save tons of - mostly redundant - code. As an “computer science veteran” (startet programming with fortran77, PL/1, Cobol, Pascal…) it seems to be nessecary to dive into jinja
thanks @123, yes your template works well to!
My 1st reply should have inserted after your post, but was added at the end, after example from @Troon. Seems that “reply” to any post will put at the end
I want to understand your (both) examples so I have to learn basics (hard in my age