Hello,
I’m trying to create an alarm clock that can be easily adjusted by using an input_number
.
Currently I have the alarm clock setup so when I log a feeding (for new born), it will automatically adjust the alarm clock 2 hours into the future. This part works perfectly, the issue is that it’s static, meaning its always two hours. Sometimes though we may want to have the alarm be 2.5 or 3 hours into the future.
My goal, is to use an input_number
to dynamically set the time between feedings. For example, lets say I log a feeding at 2pm. The next part of the automation should check the current time, then add the state of the input_number
to be the next feeding time. So if its 2pm and the input_number
is set to 3, the next feeding time would be 5pm.
I also want to make sure any time the input_number
is adjusted it automatically adjusts the next feeding time. Following the same example above, the next feeding time is 5pm but later I decide to change the input_number
to 3.5, now the next feeding time should be 5:30pm. (btw I only plan on doing half hour increments).
I hope this post makes sense to someone that can help me. I know dealing with time is often a pain. Maybe I’m going about this completely wrong and someone can steer me in the right direction.
How my current alarm clock works.
Adding a feeding entry triggers this script, which adjusts the next feeding time 2 hours in the future.
update_next_feed:
alias: Update Next Feed
mode: single
sequence:
- service: input_datetime.set_datetime
data:
datetime: '{{ (now().strftime("%s")|int +7200|int) |timestamp_custom("%Y-%m-%d %H:%M:%S", false) }}'
target:
entity_id: input_datetime.feeding_time
- service: notify.caspillers
data:
message: "clear_notification"
data:
tag: "feed"
Then in order for the alarm to trigger I use a sensor to convert the input_datetime.feeding_time
into hours and minutes.
- platform: template
sensors:
convert_feedtime:
friendly_name: Convert Feed Time
value_template: "{{ states.input_datetime.feeding_time.attributes.timestamp | timestamp_custom('%H:%M') }}"
Followed by another sensor that compares the current time to the sensor above sensor.covert_feedtime
. When this sensor becomes true, the alarm clock is triggered to notify me.
- platform: template
sensors:
compare_feedtime:
friendly_name: Compare Feed Time
value_template: "{{states('sensor.time') == states('sensor.convert_feedtime')}}"