Wake-up light alarm with sunrise effect

I am having issues getting this to run, its meant to run around 0700 each day.

Automation YAML

description: ""
use_blueprint:
  path: sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    light_entity: light.color_temperature_light_6
    min_mired: 500
    check_entity: none
    pre_sunrise_actions:
      - service: media_player.media_stop
        data: {}
        target:
          entity_id: media_player.bedroom
    manual_time: "07:00:00"

Blueprint

variables:
  light_entity: light.color_temperature_light_6
  sensor: none
  sunrise_duration: 25
  start_brightness: 1
  end_brightness: 254
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  manual_time: '07:00:00'
  seconds: '{{float(sunrise_duration) * 60}}'
  min_mired: 500
  start_mired: '{{state_attr(light_entity, ''max_mireds'')}}'
  end_mired: '{{[state_attr(light_entity, ''min_mireds'')|int(0), min_mired|int(0)]|max}}'
  tick_time: '{{float(seconds) / float(range_brightness)}}'
  check_entity: none
trigger:
  - platform: time_pattern
    minutes: '*'
condition: []
action:
  - wait_template: '{{sensor == ''none'' or as_timestamp(states(sensor), None) != None}}'
  - wait_template: >-
      {{0 < as_timestamp(states(sensor) if sensor != 'none' else
      states('sensor.date') ~ ' ' ~ manual_time) -
      as_timestamp(states('sensor.date_time_iso')) <= float(seconds) and
      states(check_entity) in ['unknown', 'on', 'home']}}
  - choose: []
    default:
      - service: media_player.media_stop
        data: {}
        target:
          entity_id: media_player.bedroom
  - condition: template
    value_template: '{{sensor == ''none'' or as_timestamp(states(sensor), None) != None}}'
  - condition: template
    value_template: >-
      {{0 < as_timestamp(states(sensor) if sensor != 'none' else
      states('sensor.date') ~ ' ' ~ manual_time) - as_timestamp(now()) <=
      float(seconds) and states(check_entity) in ['unknown', 'on', 'home']}}
  - choose:
      - conditions:
          - '{{state_attr(light_entity, ''min_mireds'') != None}}'
        sequence:
          - service: light.turn_on
            data:
              brightness: '{{start_brightness}}'
              color_temp: '{{start_mired}}'
            entity_id: light.color_temperature_light_6
    default:
      - service: light.turn_on
        data:
          brightness: '{{start_brightness}}'
        entity_id: light.color_temperature_light_6
  - repeat:
      while:
        - '{{sensor == ''none'' or as_timestamp(states(sensor), None) != None}}'
        - >-
          {{0 < as_timestamp(states(sensor) if sensor != 'none' else
          states('sensor.date') ~ ' ' ~ manual_time) - as_timestamp(now()) <=
          float(seconds)}}
      sequence:
        - delay: '{{tick_time}}'
        - choose:
            - conditions:
                - >-
                  {{0 < state_attr(light_entity, 'brightness') | int(0) <
                  end_brightness | int}}
                - >-
                  {{sensor == 'none' or as_timestamp(states(sensor), None) !=
                  None}}
                - >-
                  {{0 < as_timestamp(states(sensor) if sensor != 'none' else
                  states('sensor.date') ~ ' ' ~ manual_time) -
                  as_timestamp(now()) <= float(seconds)}}
              sequence:
                - choose:
                    - conditions:
                        - '{{state_attr(light_entity, ''min_mireds'') != None}}'
                      sequence:
                        - service: light.turn_on
                          data:
                            brightness: >-
                              {{(float(end_brightness) -
                              (float(range_brightness) *
                              (as_timestamp(states(sensor) if sensor != 'none'
                              else states('sensor.date') ~ ' ' ~ manual_time) -
                              as_timestamp(now())) / float(seconds))) | int(0)}}
                            color_temp: >-
                              {{(float(end_mired) + (float(start_mired) -
                              float(end_mired)) * ((as_timestamp(states(sensor)
                              if sensor != 'none' else states('sensor.date') ~ '
                              ' ~ manual_time) - as_timestamp(now())) /
                              float(seconds))) | int(0)}}
                          entity_id: light.color_temperature_light_6
                  default:
                    - service: light.turn_on
                      data:
                        brightness: >-
                          {{(float(end_brightness) - (float(range_brightness) *
                          (as_timestamp(states(sensor) if sensor != 'none' else
                          states('sensor.date') ~ ' ' ~ manual_time) -
                          as_timestamp(now())) / float(seconds))) | int(0)}}
                      entity_id: light.color_temperature_light_6
  - choose: []
    default: []
mode: single
max_exceeded: silent
id: '1660167603662'
alias: Wake-up light alarm with sunrise effect
description: ''

getting this from the trace timeline:


In 'template' condition: ValueError: Template error: as_timestamp got invalid input 'unknown 07:00:00' when rendering template '{{0 < as_timestamp(states(sensor) if sensor != 'none' else states('sensor.date') ~ ' ' ~ manual_time) - as_timestamp(states('sensor.date_time_iso')) <= float(seconds) and states(check_entity) in ['unknown', 'on', 'home']}}' but no default was specified```

I came here with this same error. Anyone have any thoughts?

In 'template' condition: ValueError: Template error: as_timestamp got invalid input 'unknown 07:00:00' when rendering template '{{0 < as_timestamp(states(sensor) if sensor != 'none' else states('sensor.date') ~ ' ' ~ manual_time) - as_timestamp(states('sensor.date_time_iso')) <= float(seconds) and states(check_entity) in ['unknown', 'on', 'home']}}' but no default was specified```

I found the answer in this post…

Apparently I didn’t have a ‘date_time_iso’ sensor.

I tried to use this blueprint as well, but didn’t get it to work right out of the box.

To make it work I had to replace every call to now() with states(''sensor.date_time_iso'').

I assume that now() is not aware of the time zone and sends a wrong time which results in every condition being false.

@Sbyx is there a way to increase the “steps” of the automation? I changed the trigger to
seconds: '/10'
and even though the automation runs every 10 seconds it effectively only updates the light every minute. When it’s not updating the light, I get the message: Stopped because only a single execution is allowed.

Thank you for your help.

Running the latest version of homeassistant.

I have come to the conclusion that I need som help setting up the required sensors, after spending too much time trying to do it myself.

I have enabled the ‘date_time_iso’ and date sensors in my configuration.yaml file. The blueprint also works when I set the time manually in the automation. But I am using an iPhone and have to create a timestamp sensor manually.

I have read through all the posts and tried other solutions from the forum and documentation but the created sensor replies either ‘unknown’ or ‘unavailable’. I have tried creating a time_date helper with both date and time or only time. Both with the same result.

The code I have tried…

template:
  - sensor:
      - name: whatever
        device_class: timestamp
        state: "{{ states('input_datetime.something') | as_datetime }}"
sensor:
  - platform: template
    sensors:
      alarm_time:
        value_template: "{{states('sensor.date') ~ ' ' ~ states('input_datetime.XYZ')}}"
        device_class: timestamp

What am I doing wrong?

Thank you.

-------------------- UPDATE -----------------------
My solution is using today_at() and an automation updating the sensor at 0:05.

- sensor:
    name: "Alarm tid med dato"
    device_class: timestamp
    state: "{{today_at(states('input_datetime.alarm'))}}"

I only need to find out how to update the sensor input_datetime_alarm with the app shortcuts on iPhone.

In shortcuts on iPhone the time is displayed with a dot but home assistant needs the time with a semicolon. So instead of 12.00 it has to be 12:00. That can be changed in shortcuts.

1 Like

Can you please show an example how to implement it, i cannot figure it out.
Would love to use this blueprint.

I’m having interesting problems when trying to use next alarm from phone. I could not find any information about these errors. Same thing happens with bare google clock and default Oneplus clock seems to transfer data correctly to HA.

* Error while executing automation automation.wake_up_light_alarm_with_sunrise_effect: In 'template' condition: TypeError: forgiving_as_timestamp() takes 1 positional argument but 2 were given
* Error while executing automation automation.wake_up_light_alarm_with_sunrise_effect: In 'template' condition: AttributeError: 'dict' object has no attribute 'lower'

image

Worked like a charm “straight out of the box”, thanks!
But would like a “built in” option to turn the lights off after x time from alarm.
As of now you can add a script in “Post-sunrise actions” with delays and stuff but it’s still a secondary script which clutters up things imho.

1 Like

Hello,

I cannot get this blueprint to work; tried different lamps but they don’t turn on. I really would like to use this blueprint.

Below a copy of my config.yaml

' # Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
frontend:
  themes: !include_dir_merge_named themes
# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

light:
  - platform: group
    name: Eetkamer Lampen
    entities:
      - light.6_eetkamer
      - light.7_eetkamer
      - light.8_eetkamer
  - platform: group
    name: Woonkamer Lampen
    entities:
      - light.1_woonkamer
      - light.2_woonkamer
      - light.3_woonkamer
      - light.4_woonkamer
      - light.5_woonkamer
      - light.schemerlamp_woonkamer
      - light.wall_cabinet
  - platform: group
    name: Keuken Lampen
    entities:
      - light.9_keuken
      - light.10_keuken
      - light.11_keuken
      - light.12_keuken
      - light.13_keuken
  - platform: group
    name: Lampen 1e verdieping
    entities:
      - light.9_keuken
      - light.10_keuken
      - light.11_keuken
      - light.12_keuken
      - light.13_keuken
      - light.1_woonkamer
      - light.2_woonkamer
      - light.3_woonkamer
      - light.4_woonkamer
      - light.5_woonkamer
      - light.6_eetkamer
      - light.7_eetkamer
      - light.8_eetkamer
      - light.schemerlamp_woonkamer
      - light.wall_cabinet
  - platform: group
    name: Master bedroom
    entities:
      - light.spots_master_bedroom
      - light.wall_cabinet
camera:
  - platform: ffmpeg
    input: rtsp://192.168.11.182:8554/voordeur
    name:  voordeur
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat' '

And below the blueprint in .yaml:

' alias: Wake-up light alarm with sunrise effect 3
description: ""
use_blueprint:
  path: sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    light_entity: light.master_bedroom_2
    manual_time: "06:25:00"
    start_brightness: 53 

What is wrong?

Regards Niels

Anyone got good suggestion for the bulb which starts from very low light. Ikea bulbs arn’t good for this, they are too bright even in lowest setting.

Someone used it with an iPhone? Because I don’t have the “next alarm” sensor…

I have an iPhone and sync my working hours to my calendar, is there any way you can implement that I can have a event trigger instead of time stamp?

I have tried to figure out how to produce a time stamp entity from calendar but with no luck.

Any one that have any pointers?

1 Like

This Wake-Up-Automation is awesome! Thanks for your work.
I don’t always stay up at the same time. Is it possible to adjust the Wake-Up-Time on the “Homescreen” of my HA? I tried with a Time-Helper but as you explained, it doesn’t work. A Date&Time-Helper work but it isn’t nice to change the Date every Day. Any Ideas how i can solve this?

I currently use the innr zigbee bulbs which dim to a fairly low light. I have 2 colour temperature varying ones in our bedside lights that work quite well.

I’m fairly new to HA, but I found a possible solution to your issue. The below reference is a way to set the time helper to a timestamp. However, I did also have to use an automation to update_entity at 2:30 each morning.

I have tried the solution from deathbybandaid but newer got them to work.

I use the today_at function which creates a sensor with todays date. You can then create an automation or a trigger to update the sensor at a given time.

- sensor:
    name: "Alarm tid med dato"
    device_class: timestamp
    state: "{{today_at(states('input_datetime.alarm'))}}"```

I left a comment on the blueprint thread that is relevant here. I’m in the process of finding a replacement for my code editor that I actually like to code in (I write python mostly), and would love some help achieving some of my goals in a fork of the blueprint.

This is essentially what I’d like a dashboard for my wife to look like, We have 3 kids with completely different morning routines (3 schoolbus pickup times, over the span of 3 hours!), and I’d like her to be able to easily adjust a few things without having to learn HA at all. I’m working out some quirks before migrating from a Hue Bridge.

image

template:
  - sensor:
    - name: timestamp_sam_work_wakeup_time
      device_class: timestamp
      state: "{{ today_at(states('input_datetime.sam_work_wakeup_time')) }}"

  - sensor:
    - name: timestamp_sam_work_wakeup_time_start
      state: "{{  (today_at(states('input_datetime.sam_work_wakeup_time')) - timedelta(minutes=(states('input_number.sunrise_wakeup_time_duration_sam_work')|int))).strftime('%-I:%M %p') }}"

I then have a couple helpers for setting a time, and possibly a duration if I can figure out how to modify the blueprint.

I then had to add an automation to update_entities whenever a the duration or the time has a change. I also have a trigger for 2:30AM to make sure the today_at gets modified before I need to wake up.

Edit: It’s on my list to try and add some logic to the template sensors to determine if the time helper time is already passed for the day.

Also, it would almost be TOO HELPFUL if HA were to have a built-in scheduling/caldav service. HA could then allow us to use a UI to add calendar events with recurrence, with entity objects that expose datetime versus timestamp. Calendar entity for next_event would also be incredibly useful. A calendar system could then incorporate auto-adjustments for stuff like Holidays, or other dates that a workplace schedules off (for instance, where I work, I get Thanksgiving AND the Friday after off). With a calendar system, it would also be able to modify a single instance of a recurring event and remove a single occurance when needed,

I want to use this automation with a light that used the WLED integration.
I’m using a Wemos d1 mini with a ws2812 ledstrip inside a diy 3d printed moodlight.
Unfortunately it’s currently not working, can someone make it compatible with WLED ?