Time offset

I am attempting to create a sunrise simulation using my bedroom lamps and an input:date_time. I have the basic automation but I am looking for an efficient way to offset the time so the light is on full at the alarm time not 30 minutes after.

here is my current automation:

  alias: wakeup_lights
  trigger:
  - platform: time
    at: input_datetime.alarm_time
  action:
  - service: light.turn_on
    data:
      transition: 1800
      rgb_color:
      - 255
      - 255
      - 255
      brightness_pct: 100
      entity_id:
      - light.bedside_light
      - light.feit_bedroom1
  mode: single

Any help is greatly appriciated.

1 Like

I have finally found the same question I have, only to find that it wasn’t answered :cry:

@Greg_Pendleton Were you able to solve it?

Can anyone give a hand?

Need to trigger 30 minutes before ‘input_datetime’

Here is the template that has been working for me:

platform: template
value_template: >-
  {{((state_attr('input_datetime.alarm_time', 'timestamp') - 1800) |
  timestamp_custom('%H:%M', False)) == ((now().timestamp()) |
  timestamp_custom('%H:%M')) }}

For some reason, this solution didn’t work for me.
Here is what I did:

My time/date helper: input_datetime.morning_alarm

My config entry:

template:
  - sensor:
      unique_id: "offset_alarm"
      state: "{{ states('input_datetime.morning_alarm') | as_datetime - timedelta(minutes = 30) }}"
      device_class: timestamp

Automation YAML (relevant part)

alias: "Morning Lights: Bedroom"
description: "Gradually Turn on the lights "
trigger:
  - platform: time
    at: sensor.offset_alarm

What did I miss?

Interesting solution, is this code directly under the “trigger” tag inside the automation YAML?

Yes, here’s the block:

trigger:
  - platform: template
    value_template: >-
      {{((state_attr('input_datetime.alarm_time', 'timestamp') - 1800) |
      timestamp_custom('%H:%M', False)) == ((now().timestamp()) |
      timestamp_custom('%H:%M')) }}
action:

1 Like

Thanks to both of you, but this was the one that worked for me straight away. :ok_hand: