thanks for sharing this. but i cannot understand the automation.
The time is suppose to be dynamic, right? Shouldn’t it follows the time I select in the input_select dropdown? The automation seems to work only on 6.20.
ah… that’s what I am afraid of. it seems impractical to repeat the block of codes for every input_select options. Imagine, if I have 50 options, I have to repeat the same automation rule (with changes to the time) for 50 times! The most practical way to approach this is via loop but I can’t figure out how to do so in HASS.
Not a perfect way but… triggering an automation every…5 min. and having a condition comparing actual time with input_select state:
automation:
- alias: "Alarm clock"
trigger:
platform: time
minutes: '/5'
condition:
platform: template
# this will report true if time in input_select (in format HH:MM ) is equal to actual time
value_template: '{{ now.time().strftime("%H:%M") == states.input_select.alarm_clock.state }}'
action:
#your action here
thanks a lot. i have tried it. for action, i just made it to send notification via pushbullets. when the alarm is triggered, I received countless notifications non-stop. any idea what went wrong?
Can you post some logs from alarm triggering? I haven’t tested the code on my config, as I have only 3 options in my input_select, but tested the condition on template editor from hass page and it return False almost all the time, so in theory shouldn’t trigger so often.
it works like a charm this morning. I have modified the script to add another input_boolean of “Weekdays Only” so that the alarm only runs on weekdays if it is ‘On’. Here is what i did…
input_boolean:
alarmweekday:
name: Weekdays Only
initial: off
icon: mdi:alarm
automation:
- alias: 'Alarm Clock'
trigger:
platform: time
minutes: '/15'
seconds: 0
condition:
- platform: state
entity_id: input_boolean.alarmstatus
state: 'on'
- platform: template
value_template: '{% if is_state("input_boolean.alarmweekday", "on") %}{{ now.time().strftime("%H:%M") == states.input_select.alarmclock.state and (now.time().strftime("%a") == "Mon" or now.time().strftime("%a") == "Tue" or now.time().strftime("%a") == "Wed" or now.time().strftime("%a") == "Thu" or now.time().strftime("%a") == "Fri") }}{% else %}{{ now.time().strftime("%H:%M") == states.input_select.alarmclock.state }}{% endif %}'
action:
service: notify.notify
data:
message: 'Time to Wake Up'
title: ""
It seems there is a problem with the code. The slider value for below 10 is only one digit, whereas the below 10 value for now.time().strftime("%H") or now.time().strftime("%M") are zero-padded. So, the above conditional statement for hour or minute below 10 will always return false.
To rectify this, just change to this…
now.time().strftime("%-H")
or now.time().strftime("%-M")
I believe you could just move the value template line into the trigger section. That way you don’t need the part that checks the time every 15 minutes. so far it works for me.