Wake-up light alarm with sunrise effect

Super, it’s working just fine. Many thanks!!

Great to hear!
I’d be interested to hear if the alarm is now matching your input_datetime entity and not the manual alarm setting in the Automation.

Reason being when I check the state of the sensor.wake_up_alarm in Dev Tools Template, I get “unknown”.

I think there’s an issue with the Device Class “timestamp” expecting a different format than the datetime string provided by the input_datetime entity, I’m working through that now…

Ok, I’ve now fixed my sensor so it’s outputting correctly with the timestamp device class. I needed to change the template state as follows:

{{ (states('input_datetime.wake_up_alarm') | as_datetime | as_local).isoformat() }}

My sensor now outputs as expected:

I also worked out how to add it as a helper entity through the UI in the meantime :wink:

Solution found thanks to this post!

Hi, could it be set up like this:

  • I say a command to Siri like Hey, Siri wakeup light at 8 am
  • Siri sets up the automation + standard alarm (I would like to avoid situation that I trigger it for example when I’m on Holidays and my parents are in our home)

Is there a way to do it or maybe there are other better solutions?

Hi,

I’ve been trying to set an alarm timestamp sensor, in order to be able to change from the dashboard the time I want the automation to run.

I created a time helper input_datetime.wake_up_alarm, and added a sensor in templates.yaml :

sensor:
  - name: "Wake Up Alarm"
    unique_id: template_se_alarm_01
    state: "{{ (states('input_datetime.wake_up_alarm') | as_datetime | as_local).isoformat() }}"
    device_class: timestamp

When I set the alarm timestamp sensor to sensor.wake_up_alarm, it doesn’t work as expected.

Am I missing something there ? Could anyone help me ? Thanks

Same here, I am also confused. The help says it needs a “Sensor with timestamp of next alarm with device_class: timestamp”. I tried a template sensor that returns datetime as well as isoformat.

{% set alarm_time = state_attr('sensor.pixel_5_next_alarm', 'Time in Milliseconds') / 1000 %}
{% set alarm_time_dt = as_datetime(alarm_time)| as_local %} 
{{alarm_time_dt is datetime}}
{{alarm_time_dt}} # also alarm_time_dt.isoformat()

Both options raising the error

Error: 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

The helper in all cases show a valid value, unsure why it’s unknown to the blueprint.

Any help is welcome!

1 Like

Just realizing the problem is states('sensor.date_time_iso'). I don’t have such a sensor. What should it yield?

@TomTom101 Your hint with the ISO timestamp gave me the right place to look. You have to add the following integration: Time & Date - Home Assistant

Thanks @patti9000! That was the missing piece, no more errors!

Hey guys, Hey @Sbyx,

I have enhanced the Wake-up Light Alarm Blueprint with a few features that I find useful:

A new option called "ignore_future_alarms" has been added. When enabled, alarms set for future days will be ignored, and the manual alarm time will be used instead.
The logic has been adjusted to better handle various alarm situations, including invalid or future alarms.

These changes allow for more flexible use of the blueprint, especially for those who want to use both daily and specific alarms.

Here is the updated code:

blueprint:
  name: Wake-up light alarm with sunrise effect
  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
    timestamp_sensor:
      name: Alarm timestamp sensor
      description: "Sensor with timestamp of next alarm with device_class: timestamp (set to 'none' for manual alarm time)"
      default: none
      selector:
        entity:
          device_class: timestamp
    manual_time:
      name: Manual alarm time
      description: Time to trigger alarm every day if timestamp sensor is not set or ignored. Settings at or shortly after midnight will not work as expected!
      default: "7:00:00"
      selector:
        time: {}
    ignore_future_alarms:
      name: Ignore future alarms
      description: If enabled, alarms set for future dates will be ignored and the manual time will be used instead.
      default: false
      selector:
        boolean: {}
    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: {}
variables:
  light_entity: !input "light_entity"
  sensor: !input "timestamp_sensor"
  sunrise_duration: !input "sunrise_duration"
  start_brightness: !input "start_brightness"
  end_brightness: !input "end_brightness"
  range_brightness: "{{float(end_brightness)-float(start_brightness)}}"
  manual_time: !input "manual_time"
  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(0), min_mired|int(0)]|max}}"
  tick_time: "{{float(seconds) / float(range_brightness)}}"
  check_entity: !input "check_entity"
  ignore_future_alarms: !input "ignore_future_alarms"
trigger:
  - platform: time_pattern
    minutes: "*"
condition: []
action:
  - variables:
      sensor_time: >
        {% if sensor != 'none' and states(sensor) != 'unavailable' and as_timestamp(states(sensor)) %}
          {% if ignore_future_alarms and as_timestamp(states(sensor)) | timestamp_custom('%Y-%m-%d') > now().strftime('%Y-%m-%d') %}
            {{ states('sensor.date') ~ ' ' ~ manual_time }}
          {% else %}
            {{ states(sensor) }}
          {% endif %}
        {% else %}
          {{ states('sensor.date') ~ ' ' ~ manual_time }}
        {% endif %}
  - wait_template: >
      {{ 0 < as_timestamp(sensor_time) - as_timestamp(states('sensor.date_time_iso')) <= float(seconds) and states(check_entity) in ['unknown', 'on', 'home'] }}
  - choose: []
    default: !input "pre_sunrise_actions"
  - service: light.turn_on
    data:
      brightness: "{{ start_brightness }}"
      color_temp: "{{ start_mired if state_attr(light_entity, 'min_mireds') != None else omit }}"
    entity_id: !input "light_entity"
  - repeat:
      while:
        - condition: template
          value_template: >
            {{ 0 < as_timestamp(sensor_time) - as_timestamp(now()) <= float(seconds) }}
      sequence:
        - delay: "{{ tick_time }}"
        - service: light.turn_on
          data:
            brightness: >
              {{ (float(end_brightness) - (float(range_brightness) * (as_timestamp(sensor_time) - as_timestamp(now())) / float(seconds))) | int(0) }}
            color_temp: >
              {% if state_attr(light_entity, 'min_mireds') != None %}
                {{ (float(end_mired) + (float(start_mired) - float(end_mired)) * ((as_timestamp(sensor_time) - as_timestamp(now())) / float(seconds))) | int(0) }}
              {% else %}
                {{ omit }}
              {% endif %}
          entity_id: !input "light_entity"
  - choose: []
    default: !input "post_sunrise_actions"
mode: single
max_exceeded: silent

Let me know what you think!

Hi,
I’m using this blueprint for several months without any problem.

I desactivate it for holidays a week ago and now it’s not working anymore !
I have this message :

Erreur : In 'template' condition: ValueError: Template error: as_timestamp got invalid input 'unknown 06:50: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

Do you have any idea of what’s doing wrong ?
Thanks

I’m up to date with core and modules.

1 Like

I was starting using it today and got the same error.

update:

have a look here:

1 Like

Perfect ! It works for me !

Many thanks UsefulVid !

This is great, I recently started using it and appreciate the blueprint! Could it be modified to also accept a “Do not run if Sun has risen” sensor? Or some way to gate it between certain hours?

When using my Next Alarm as the trigger it’s less useful if I have an afternoon alarm (or in the summer when the alarm is way after the sun has come up so I wouldn’t need the automation to fire)

I would like to achieve the following:

I set the alarm time with an input_datetime helper. I would like to use this helper as input for your blueprint. I then set the time offset for sunrise in the blueprint. Now I also want a Sonos speaker to start playing a song at the beginning of sunrise. Here, however, the volume should be turned up slowly. There is also another blueprint for this. However, this second blueprint also requires a start time as input. Here I would like to use the start time of the sunrise from your blueprint.

How do I get this time?

Like many others, I was looking for a way to use this great blueprint with a real colour gradient. I found various solutions on the Internet, mostly based on scripts. Using my modest yaml skills, I have now created a new blueprint.

In principle, I first removed the colour temperature. I have not yet found a way to combine a temperature gradient with a colour gradient.

Next, I gave the user the option of entering 5 RGB colours for the colour gradient. It took me a lot of time, but I think everything works as it should now. I would be delighted to receive feedback and happy if you could further develop and optimise this blueprint.

blueprint:
  name: Wake-up light alarm with colorized sunrise effect
  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
          multiple: false
    timestamp_sensor:
      name: Alarm timestamp sensor
      description: 'Sensor with timestamp of next alarm with device_class: timestamp
        (set to ''none'' for manual alarm time)'
      default: none
      selector:
        entity:
          device_class:
          - timestamp
          multiple: false
    manual_time:
      name: Manual alarm time
      description: Time to trigger alarm every day if timestamp sensor is not set.
        Settings at or shortly after midnight will not work as expected!
      default: '7:00:00'
      selector:
        time: {}
    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:
          multiple: false
    sunrise_duration:
      name: Sunrise duration
      description: The sunrise will start the configured number of minutes before
        the timestamp.
      default: 25
      selector:
        number:
          min: 1.0
          max: 60.0
          step: 1.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
    rgb_color_1:
      name: Color 1
      description: The start-color of the sunrise simulation
      default: [112,21,0]
      selector:
        color_rgb:
    rgb_color_2:
      name: Color 2
      description: The second color of the sunrise simulation
      default: [146,70,22]
      selector:
        color_rgb:
    rgb_color_3:
      name: Color 3
      description: The third color of the sunrise simulation
      default: [178,116,49]
      selector:
        color_rgb:
    rgb_color_4:
      name: Color 4
      description: The fourth color of the sunrise simulation
      default: [208,162,82]
      selector:
        color_rgb:
    rgb_color_5:
      name: Color 5
      description: The end color of the sunrise simulation
      default: [237,210,120]
      selector:
        color_rgb:
    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
  sensor: !input timestamp_sensor
  sunrise_duration: !input sunrise_duration
  start_brightness: !input start_brightness
  end_brightness: !input end_brightness
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  manual_time: !input manual_time
  seconds: '{{float(sunrise_duration) * 60}}'
  tick_time: '{{float(seconds) / float(range_brightness)}}'
  check_entity: !input check_entity
  rgb_color_1: !input rgb_color_1
  rgb_color_2: !input rgb_color_2
  rgb_color_3: !input rgb_color_3
  rgb_color_4: !input rgb_color_4
  rgb_color_5: !input rgb_color_5
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: !input pre_sunrise_actions
- 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}}'
      entity_id: !input light_entity
  default:
  - service: light.turn_on
    data:
      brightness: '{{start_brightness}}'
    entity_id: !input light_entity
- 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:
                transition: '{{seconds / 4}}'
                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)}}'
                rgb_color: |
                  {% if state_attr(light_entity, 'brightness') | int(0) <= 20 %}
                    {{rgb_color_1 | list}}
                  {% elif state_attr(light_entity, 'brightness') | int(0) <= 40 %}
                    {{rgb_color_2 | list}}
                  {% elif state_attr(light_entity, 'brightness') | int(0) <= 80 %}
                    {{rgb_color_3 | list}}
                  {% elif state_attr(light_entity, 'brightness') | int(0) <= 130 %}
                    {{rgb_color_4 | list}}  
                  {% else %}
                    {{rgb_color_5 | list}}
                  {% endif %}  
              entity_id: !input light_entity
          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: !input light_entity
- choose: []
  default: !input post_sunrise_actions
mode: single
max_exceeded: silent

Here are a few good suggestions for a sunrise colour gradient:
https://piktochart.com/tips/sunrise-color-palette

To create my own gradient or to get the RGB code, I used this website:
https://colordesigner.io/gradient-generator

2 Likes

Excellent ! I will try it when I’m back at home.

I have tested with an IKEA Tradfri LED2109G6 but I get no brightness ramping…

I think that the problem is that this bulb only support transitions on 1 attribute at a time. (as mentionned here : IKEA LED2109G6 control via MQTT | Zigbee2MQTT)

I tested it with a Philips Hue (White & Ambiance Colour) bulb and it worked well. A simultaneous transition of brightness and colour doesn’t seem to be a problem here.

Great idea, i try this one for tomorrow :slight_smile: