I have used [sleep alarm to HA] to create an input.datetime helper in my HA. This all works well.
I wrote this code to activate the wake up light. However the trigger does not like the time offset. I have used various options but all do not work. I would like some help by setting up the trigger properly to the wake up light starts 20’ before the actual alarm.
alias: Wake Up Light
description: Gradually increase light brightness to a defined percentage before wake-up time
trigger:
- platform: time
at: >
{{ (states('input_datetime.yphone_alarm') | as_datetime - timedelta(minutes=20)).time() }}
variables:
max_brightness: 102 # 40% of 255
action:
- service: light.turn_on
target:
entity_id: light.bedroom_spots
data:
brightness: 5
- delay: "00:00:30"
- repeat:
while:
- condition: template
value_template: >
{{ state_attr('light.bedroom_spots', 'brightness') | int < max_brightness }}
sequence:
- service: light.turn_on
target:
entity_id: light.bedroom_spots
data:
brightness: >
{{ [state_attr('light.bedroom_spots', 'brightness') | int + 5, max_brightness] | min }}
- delay: "00:00:30"
- service: logbook.log
data:
name: "Wake Up Light"
message: "Brightness reached {{ state_attr('light.bedroom_spots', 'brightness') }}."
If you want to use a template like that, to calculate a time for a trigger you need to use a Template trigger (as demonstrated above by Colton). Though I would suggest using the following simpler version:
alias: Wake Up Light
description: Gradually increase light brightness to a defined percentage before wake-up time
trigger:
- platform: time
at:
entity_id: input_datetime.yphone_alarm
offset: "-00:20:00"
Well somethings wrong with your system. I took the screenshot from the same version. I even worked on that section of code recently. The YAML I provided 100% works.
PS: here’s screenshots of both your code and mine showing yours giving me that error and mine working fine. I know it’s apples and oranges. I’d like to figure out why yours doesn’t work on my system though…
I’ve just read up with the threat. This is indeed the problem. The helper input_datetime is not considered a sensor and thus does not work. When can we expect an update of HA?