Not willing to wait for the update from HA I hava tried idea. However it doesn’t seem to work for me. I’ve added a printscreen of my log files where basically nothing happens when the set time is reached.
This is now my code (same as yours)
alias: Wake Up Light
description: >-
Gradually increase light brightness to a defined percentage before wake-up
time
triggers:
- value_template: >-
{{ (as_timestamp(states('input_datetime.yphone_alarm')) - 1200) |
timestamp_custom('%H:%M:%S', false) == states('sensor.time').state }}
trigger: template
actions:
- target:
entity_id: light.bedroom_spots
data:
brightness: 5
action: light.turn_on
- delay: "00:00:30"
- repeat:
while:
- condition: template
value_template: >
{{ state_attr('light.bedroom_spots', 'brightness') | int <
max_brightness }}
sequence:
- target:
entity_id: light.bedroom_spots
data:
brightness: >
{{ [state_attr('light.bedroom_spots', 'brightness') | int + 5,
max_brightness] | min }}
action: light.turn_on
- delay: "00:00:30"
- data:
name: Wake Up Light
message: >-
Brightness reached {{ state_attr('light.bedroom_spots', 'brightness')
}}.
action: logbook.log
variables:
max_brightness: 102
In order for me to test, I created a Helper, and selected Date and Time Helper (there are helpers for date and a helper for time separately but I chose the combined one)
I have tried this. I am not sure what happens.
It triggered the automation directly after I changed the time to current time +21 min. This happened twice but not always.
The automation was never triggered when the time was changed to more than 21 min in the future and the time -20 min was reached.
Excuse me if this is a stupid question I have just started working with HA and yaml coding. I think I understand the idea. However how do I make a timestamp template sensor? According to Chat GPT I have to change the configuration.yaml code using the add-on file editor. Is that right?
Okay I’m getting there. I have now got a sensor. giving the time until the alarm should be triggered. Wouldn’t it be clearer if the sensor just copies the time from the alarm so I can then use the code suggested by you earlier?
I have a similar use case. I have an input_datetime with time only, that specifies the time for the house to wakeup. So for example a value of “06:00:00” would indicate a wakeup time of 6 AM.
hvac_wakeup_time:
name: Wakeup Time
has_date: false
has_time: true
This worked fine as an automation trigger when done like this:
- triggers:
- trigger: time
at: input_datetime.hvac_wakeup_time
Then i decided I really needed to use offsets. And so I attempted using the input_datetime with an offset, which is not supported. So I created a template sensor and that did not work either. It turns out that the time trigger requires the sensor to have a device_class of timestamp and if it doesn’t have the device_class it silently ignore the trigger :-(. Because it’s a timestamp it needs to be a fully formed ISO timestamp e.g. (2024-12-16T12:00:00+00:00)
So to go from the input_datetime with time only to trigger an alarm for tomorrow morning, i go to this solution. Note, if you want the alarm to trigger every day; you’ll want to have the sensor recalculate at 23:59 (I don’t need that since I have an automation that sets the input_datetime every day)
template:
- trigger:
- platform: state
entity_id: input_datetime.hvac_wakeup_time
sensor:
- name: "hvac_wakeup_time"
state: >-
{% set input_time = states("input_datetime.hvac_wakeup_time") %}
{% set tomorrow = (now() | as_timestamp + 86400) | timestamp_custom("%Y.%m.%d", True) %}
{% set time_str= tomorrow + " " + input_time %}
{% set time = strptime(time_str.strip(),"%Y.%m.%d %H:%M:%S") %}
{{ (time | as_local).isoformat() }}
device_class: timestamp