Wake-up light alarm with sunrise effect

Hi, yesterday i added this blueprint and it seems to work.
But how can i remove the manual alarm time?

I only want to start this automation, when a alarm is set otherwise it shall not start.

Can I add a possibility the blueprint only to execute if the sun is below horizon?

workday or something like being home I can check, but not state of the sun. Since I use the alarm sensor from phone, it would be also execute on for example Friday afternoon.

Hope that somebody can help me.

I tried to edit this blueprint myself but I could not figure it out so now i’am trying to make a timestamp helper so I can start using this blueprint.
I created a datetime helper called “next alarm” with the option date and time.
the time date sensors I put in my config file.
At the moment ham using the blueprint from t-guy92 because the original sometimes work and put the light after some moments to full brightness, but more often it was not working

- platform: template
    sensors:
      next_alarm:
        friendly_name: next alarm
        device_class: timestamp
        value_template: "{{ states('input_datetime.wekker_test') | as_datetime | as_local }}"

When I use template above and I look at the status I get 2023-02-28T19:03:00+00:00
I tried also the following template.

- platform: template
    sensors:
      next_alarm:
        friendly_name: "next alarm"
        device_class: timestamp
        value_template: "{{ now().strftime(states('input_datetime.wekker_test')) }}"

Then I get the following in status menu:
unknown

I don’t understand what the correct time format is that the automation need to use it as a time to start the automation.

Hi. Is it possible to setup some kind of color effect, like fading in/out between orange/red/warmwhite to simulate sunrise?

Just an idea.
Regards.

1 Like

Hello, non-linear brightness increase would be a nice addition to the great blueprint. That is very slow brightness increase in the beginning but increasingly faster towards the end.

I recently updated HA and jumped quite a few versions. The post sunrise actions don’t seem to be firing anymore. Anyone else have this issue?

I just started using HA and wanted to implement this wake-up light. Unfortunately it is not triggering for me:

In ‘template’ condition: ValueError: Template error: as_timestamp got invalid input ‘unknown’ 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’m not sure which as_timestamp() call is failing and how to debug things here. Date sensors are added to my configuration.yaml and it seems like the alarm time is also getting transfered from my phone.

Edit: Found my mistake, it is not sufficient to reload configuration.yaml, a proper restart is necessary after adding time/date sensors.

Hello, I’ve tried for a number of hours without any progress:
Trace appears to be stuck on this step:

variables:
  light_entity: light.my_light
  sensor: sensor.my_phone
  sunrise_duration: 25
  start_brightness: 1
  end_brightness: 254
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  manual_time: '7:00:00'
  seconds: '{{float(sunrise_duration) * 60}}'
  min_mired: 0
  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

State reported in developer tools as follows:
my_phone_next_alarm: 2023-04-02T10:20:00+00:00
date_time_iso: 2023-04-02T22:09:00

Any ideas where i should look into?

Having the same issue.

Tried following this but it was zero help to me: [SOLVED] Template sensor giving unknown but developer template shows true

Unfortunately, even when people try to help - sometimes HA just isn’t user friendly.

I don’t understand why this particular Blueprint insists on Sensors rather than (or including) a time input option.

I have resorted to editing the automation every single night to change the alarm time.

Is anyone able to shed some light on how I might be able to trigger the alarm based on a combination of triggers? For example only if both of the following are true:

  • device_tracker is home
  • workday sensor is true

The “Additional entity to check before sunrise is triggered” takes a single entity as input, and I’ve seen that I can create a Group Helper, but only to combine entities of the same type, so it can’t be used to combine the binary_sensor (workday) and the device_tracker, for example. Is there any way I can achieve this? I feel like basing the condition off only one of these won’t completely be what I want.

1 Like

Issue was xiaomi phone reporting incorrect xx_next_alarm values. used google clock app instead and everything functions correctly

Request that an option for a datetime input is allowed and not just sensors for alarm time.

Thanks for this, works great!
My partner and I both use it with the bedroom lights. I wonder if anyone has any ideas how if we both have an alarm set close together, they don’t both run, only the first one? (seems that if this blueprint runs twice on the same lights, the light flash between the brightnesses )

This is my version of the wake-up light :wink:

Using the google-agenda, lifx mini color and A google home mini

The automation is triggered at a specific time using a time trigger in Home Assistant. In this case, the trigger is set to 5:10 AM using the at parameter.

The automation also includes a condition that checks the description of a specific event on a calendar. This is done using a template condition that checks if the phrase “Day Shift” is included in the description of the event. If the condition is met, the automation will proceed with its actions.

When the automation is triggered, it will first turn on a specific light in the living room and set its color to a warm, morning sun color using the light.turn_on service.

Next, the automation will gradually increase the brightness of the light until it reaches 100% over a period of 20 minutes using a repeat loop and the light.turn_on service. The brightness of the light is determined by the formula brightness: "{{ (100 / (20 * 60)) * repeat.index }}", which calculates the brightness based on the index of the current loop iteration.

After the light has reached full brightness, the automation will wait for 10 minutes using the delay action before starting the music.

When the music starts, the automation will first set the volume of a specific media player to a starting level of 20% using the media_player.volume_set service.

Finally, the automation will start playing a specific YouTube video on the media player using the media_player.play_media service.

automation:
  - alias: 'Sunrise Lamp and Sound' # Name of the automation
    trigger:
      platform: time
      at: '05:10:00' # Time at which the automation should start
    condition:
      condition: template
      value_template: "{{ 'Day shift' in state_attr('calendar.dennis_work', 'description').lower() }}" # Description of the event on the calendar that must match
    action:
      - service: light.turn_on
        entity_id: light.living_room # Entity_id of the lamp you want to turn on
        data:
          brightness: 1
          rgb_color: [255, 216, 138] # RGB color of the lamp, in this case a morning sun color
      - repeat:
          while:
            - condition: state
              entity_id: light.living_room # Entity_id of the lamp you want to use
              state: 'off'
          sequence:
            - service: light.turn_on
              entity_id: light.living_room # Entity_id of the lamp you want to use
              data:
                brightness: "{{ (100 / (20 * 60)) * repeat.index }}" # Brightness of the lamp
                rgb_color: [255, 216, 138] # RGB color of the lamp, in this case a morning sun color
            - delay: "{{ 60 / 20 }}" # Delay between each step of the lamp brightness
      - delay: "00:10:00" # Delay for starting the music
      - service: media_player.volume_set
        data:
          entity_id: media_player.kitchen_sonos # Entity_id of the media player
          volume_level: 0.2 # Starting volume of the media
      - service: media_player.play_media
        data:
          entity_id: media_player.kitchen_sonos # Entity_id of the media player
          media_content_id: "https://www.youtube.com/watch?v=-wS681nhMGM" # URL of the YouTube video you want to play
          media_content_type: "music"

this is the timeline of the automation.

5:10 AM - Sunrise Lamp and Sound automation starts
5:10 AM - Living room light turns on with morning sun color
5:10-5:30 AM - Light brightness gradually increases over 20 minutes
5:20 AM - 10-minute delay before music starts
5:20 AM - Kitchen Sonos volume set to 20%
5:20 AM - YouTube video with URL https://www.youtube.com/watch?v=-wS681nhMGM starts playing on Kitchen Sonos

this is my test script.

Hello,

First thank you @Sbyx for this wonderful blueprint

Here is an updated version of it that will let you specify an input_datetime entry you’ve created in Hassio. I only tested it this week but it seems to work just fine, enjoy!

blueprint:
  name: Wake-up light alarm with sunrise effect - updated v2
  description: 'A wake-up light alarm with a brightness and color temperature sunrise
    effect. Note: Requires date_time_iso sensor in configuration, not manually executable!'
  domain: automation
  input:
    light_entity:
      name: Wake-up light entity
      description: The light to control. Turning it off during the sunrise will keep
        it off. Color temperature range is auto-detected.
      selector:
        entity:
          domain: light
    time_entity:
      name: Alarm time entity
      description: Input datetime entry. Time to trigger alarm every day. 
        Settings at or shortly after midnight will not work as expected!
      default: none
      selector:
        entity:
          domain: input_datetime
    check_entity:
      name: Additional entity to check before sunrise is triggered
      description: If set, checks if entity is 'on' or 'home' before triggering. Use
        e.g. a (workday) sensor, device_tracker or person entity.
      default: none
      selector:
        entity: {}
    sunrise_duration:
      name: Sunrise duration
      description: The sunrise will start the configured number of minutes before
        the timestamp.
      default: 25
      selector:
        number:
          min: 5.0
          max: 60.0
          step: 5.0
          unit_of_measurement: min
          mode: slider
    start_brightness:
      name: Minimum brightness
      description: The brightness to start with. Some lights ignore very low values
        and may turn on with full brightness instead!
      default: 1
      selector:
        number:
          min: 1.0
          max: 255.0
          step: 1.0
          mode: slider
    end_brightness:
      name: Maximum brightness
      description: The brightness will be transitioned from the minimum to the configured
        value.
      default: 254
      selector:
        number:
          min: 5.0
          max: 255.0
          step: 1.0
          mode: slider
    min_mired:
      name: Minimum color temperature
      description: 'The minimum color temperature to use. (0: lowest supported)'
      default: 0
      selector:
        number:
          min: 0.0
          max: 500.0
          step: 5.0
          mode: slider
          unit_of_measurement: mired
    pre_sunrise_actions:
      name: Pre-sunrise actions
      description: Optional actions to run before sunrise starts.
      default: []
      selector:
        action: {}
    post_sunrise_actions:
      name: Post-sunrise actions
      description: Optional actions to run after sunrise ends (around the alarm time).
      default: []
      selector:
        action: {}
  source_url: https://gist.github.com/sbyx/96c43b13b90ae1c35b872313ba1d2d2d
variables:
  light_entity: !input 'light_entity'
  sunrise_duration: !input 'sunrise_duration'
  start_brightness: !input 'start_brightness'
  end_brightness: !input 'end_brightness'
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  time_entity: !input 'time_entity'
  seconds: '{{float(sunrise_duration) * 60}}'
  min_mired: !input 'min_mired'
  start_mired: '{{state_attr(light_entity, ''max_mireds'')}}'
  end_mired: '{{[state_attr(light_entity, ''min_mireds'')|int, min_mired|int]|max}}'
  tick_time: '{{float(seconds) / float(range_brightness)}}'
  check_entity: !input 'check_entity'
trigger:
- platform: time_pattern
  minutes: '*'
condition: []
action:
- wait_template: '{{ 0 < as_timestamp(states(''sensor.date'') ~ ''T'' ~ states(time_entity)) - as_timestamp(states(''sensor.date_time_iso'')) <= float(seconds) and states(check_entity) in [''unknown'', ''on'', ''home''] }}'
- choose: []
  default: !input 'pre_sunrise_actions'
- condition: template
  value_template: '{{ 0 < as_timestamp(states(''sensor.date'') ~ ''T'' ~ states(time_entity)) - 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: !input 'light_entity'
  default:
  - service: light.turn_on
    data:
      brightness: '{{ start_brightness }}'
    entity_id: !input 'light_entity'
- repeat:
    while:
    - '{{ 0 < as_timestamp(states(''sensor.date'') ~ ''T'' ~ states(time_entity)) - as_timestamp(now()) <= float(seconds) }}'
    sequence:
    - delay: '{{ tick_time }}'
    - choose:
      - conditions:
        - '{{ 0 < state_attr(light_entity, ''brightness'') | int < end_brightness | int }}'
        - '{{ 0 < as_timestamp(states(''sensor.date'') ~ ''T'' ~ states(time_entity)) - 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.date'') ~ ''T'' ~ states(time_entity)) - as_timestamp(now())) / float(seconds))) | int }}'
                color_temp: '{{ (float(end_mired) + (float(start_mired) - float(end_mired)) * ((as_timestamp(states(''sensor.date'') ~ ''T'' ~ states(time_entity)) - as_timestamp(now())) / float(seconds))) | int }}'
              entity_id: !input 'light_entity'
          default:
          - service: light.turn_on
            data:
              brightness: '{{ (float(end_brightness) - (float(range_brightness) * (as_timestamp(states(''sensor.date'') ~ ''T'' ~ states(time_entity)) - as_timestamp(now())) / float(seconds))) | int }}'
            entity_id: !input 'light_entity'
- choose: []
  default: !input 'post_sunrise_actions'
mode: single
max_exceeded: silent
1 Like

Any advice on why my lights come onto maximum brightness initially at the start of the automation? It doesn’t make for the most relaxing start.

Hello Bluenight,

Thank you for sharing your code.
I don’t know if this is the correct way but I updated the blueprint code using code server.
The input date time field I could fill in my own so that looks like it is working, will see tomorrow morning if I can get on time to work ;).

I have another question, ad the entity check before sunrise I put in my workday sensor except I also have bed sensors (numeric state has to be above 1) that I want to use also in this automation but I have no idee how I could implement this, do you maybe have an idea.

Thnx in advance.

Hello @edi023

I would create a custom binary template sensor that evaluates both workday sensor and your other numeric sensors and would give this custom sensor to the blueprint automation.

Hope it make sense what I am saying :slight_smile:

Hello Bluenight,

You are making great sense :wink: .

i had the same idea and trying out somethings, hopefully I’am on the correct road.

- platform: template
    sensors:
      wekker_actief:
        friendly_name: "Wekker Actief"
        value_template: >-
          {% if is_state('binary_sensor.bed_bezet_deur', 'on') or is_state('binary_sensor.bed_bezet_kast', 'on') and is_state('binary_sensor.werkdagen', 'on') %}
              on
          {% else %}
              off
          {% endif %}

trying to figure out how to get two two more input_booleans into the mix ( 1 for holiday and 1 for weekend) :slight_smile:

Hi I’m a complet noob at coding how did you manage the cards into te sunrise effect i tried your code on github and get a @data tigger error.
Can you help please .