Use curent day name as enity_id reference in condition (alarmclock)

Hello ,
I have an alarm clock with 7 toggles named:
input_boolean.sk1_monday_toggle
input_boolean.sk1_tuesday_toggle
input_boolean.sk1_wednesday_toggle
input_boolean.sk1_friday_toggle
etc…
Now i want to check in the automation condition if the toggle of the present day is set.
this is what i have so far:

Trigger:

platform: template
value_template: >-
  {% set dow = now().strftime("%A")|lower %} {% set input =
  "input_datetime.sk1_"~dow~"_alarm" %} {{ now() >= today_at(states(input)) }} 
alias: Trigger op Date time variabelen

(this seems to work)

condition:
  - condition: state
    entity_id: input_boolean.sk1_toggle
    state: "on"
  - condition: template
    value_template: >-
      {% set dow = {%  now().strftime("%A")|lower %}  {{
      states('input_boolean.sk1_'~dow'_toggle')}} == 'on'

i have 2 conditions the main toggle alarm clock off/on
and one for each day.

But what is the correct syntax for the day toggle ?
can some on plz. help me with this ?

Gr.

1 Like
condition:
  - condition: state
    entity_id: input_boolean.sk1_toggle
    state: "on"
  - condition: template
    value_template: >-
      {{ is_state('input_boolean.sk1_' ~ now().strftime('%A')|lower ~ '_toggle', 'on') }}
1 Like

Thanks that worked !

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.