Wake-up light alarm with sunrise effect

Hi! Thanks for this really useful blueprint. I’m trying to use it so it automates with my google home alarm. Tried a few different things, but cannot get it to work.

Any ideas?

homeassistant:
  customize: !include customize.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:



# Text to speech
tts:
  - platform: google_translate

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

sensor:
  - platform: time_date
    display_options:
      - 'date'
      - 'date_time_iso'

# Google Home Alarm Sensor

  - platform: template
    sensors:
      google_home_alarm_sensor:
       value_template: '{{ as_timestamp(states("sensor.bedroom_display_alarms"))| timestamp_custom("%A %B %-d, %I:%M %p") }}'

sensor is set as a timestamp via customize.yaml

For me, it helped to add a time_date sensor with the used display options to the configuration:

sensor:
  - platform: time_date
    display_options:
      - 'date'
      - 'date_time_iso'
1 Like

Hey i try to use it too, cause it looks awesome, sadly it’s just not working i have no idee why, maybe somebody could have a look:

Config

id: '1637529339671'
alias: asjnklödsnköjldfs
description: ''
use_blueprint:
  path: Sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    light_entity: light.schrank
    sunrise_duration: 5
    manual_time: '22:16:00'

And Trace:

{
  "trace": {
    "last_step": "action/1",
    "run_id": "5ed2dde219ba157c631c1f657f8a649b",
    "state": "running",
    "script_execution": null,
    "timestamp": {
      "start": "2021-11-21T21:16:00.006709+00:00",
      "finish": null
    },
    "domain": "automation",
    "item_id": "1637529339671",
    "trigger": "time pattern",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2021-11-21T21:16:00.007855+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.asjnklodsnkojldfs",
              "state": "on",
              "attributes": {
                "last_triggered": "2021-11-21T21:15:55.330570+00:00",
                "mode": "single",
                "current": 0,
                "id": "1637529339671",
                "friendly_name": "asjnklödsnköjldfs"
              },
              "last_changed": "2021-11-21T21:15:40.225207+00:00",
              "last_updated": "2021-11-21T21:15:55.338753+00:00",
              "context": {
                "id": "20ac517926d158e53ddb7d55766c140a",
                "parent_id": "0b660c1026eddf68ca293de0e8a46b40",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "time_pattern",
              "now": "2021-11-21T22:16:00.003790+01:00",
              "description": "time pattern"
            },
            "light_entity": "light.schrank",
            "sensor": "none",
            "sunrise_duration": 5,
            "start_brightness": 1,
            "end_brightness": 254,
            "range_brightness": 253,
            "manual_time": "22:16:00",
            "seconds": 300,
            "min_mired": 0,
            "start_mired": null,
            "end_mired": 0,
            "tick_time": 1.1857707509881423,
            "check_entity": "none"
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2021-11-21T21:16:00.019584+00:00",
          "changed_variables": {
            "context": {
              "id": "b5da3c6369a20d540ee438ce9c0b408b",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "wait": {
              "remaining": null,
              "completed": true
            }
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2021-11-21T21:16:00.019999+00:00",
          "changed_variables": {
            "wait": {
              "remaining": null,
              "completed": true
            }
          },
          "result": {
            "wait": {
              "remaining": null,
              "completed": false
            }
          }
        }
      ]
    },
    "config": {
      "variables": {
        "light_entity": "light.schrank",
        "sensor": "none",
        "sunrise_duration": 5,
        "start_brightness": 1,
        "end_brightness": 254,
        "range_brightness": "{{float(end_brightness)-float(start_brightness)}}",
        "manual_time": "22:16: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"
      },
      "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": []
        },
        {
          "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.schrank"
                }
              ]
            }
          ],
          "default": [
            {
              "service": "light.turn_on",
              "data": {
                "brightness": "{{start_brightness}}"
              },
              "entity_id": "light.schrank"
            }
          ]
        },
        {
          "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.schrank"
                              }
                            ]
                          }
                        ],
                        "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.schrank"
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          }
        },
        {
          "choose": [],
          "default": []
        }
      ],
      "mode": "single",
      "max_exceeded": "silent",
      "id": "1637529339671",
      "alias": "asjnklödsnköjldfs",
      "description": ""
    },
    "blueprint_inputs": {
      "id": "1637529339671",
      "alias": "asjnklödsnköjldfs",
      "description": "",
      "use_blueprint": {
        "path": "Sbyx/wake-up-light-alarm-with-sunrise-effect.yaml",
        "input": {
          "light_entity": "light.schrank",
          "sunrise_duration": 5,
          "manual_time": "22:16:00"
        }
      }
    },
    "context": {
      "id": "b5da3c6369a20d540ee438ce9c0b408b",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "asjnklödsnköjldfs",
      "message": "has been triggered by time pattern",
      "source": "time pattern",
      "entity_id": "automation.asjnklodsnkojldfs",
      "context_id": "b5da3c6369a20d540ee438ce9c0b408b",
      "when": "2021-11-21T21:16:00.008022+00:00",
      "domain": "automation"
    }
  ]
}

Thanks for any help… i’m just lost…

Oo and i can’t see anythink in the log

Great blueprint, thanks for your work!
Is it possible to use another trigger? I tried to start the whole automation from another automation but without success. It would be nice to trigger the alarm with other enties states.

This is great, thanks OP. I prefer the lights to start fully red at brightess 1, so I bastardized this poor blueprint to work around that (my Hass skills are not great yet :slight_smile: ).

To get the starting state right I just used a pre-sunrise script to set the light to 1% brightness red. I then added an input to specify the temperature of the light in the end state, axed the whole light changing logic, and instead changed that to use the transition attribute in the light.turn_on service. As a bonus I added a post-sunrise script to crank the light to an even higher brightness and temperature since I tend to lay in bed an extra 5 mins anyways.

Since a few others were asking for something similar in the comments earlier, here’s the full automation. Not sure that I have the ability to troubleshoot much, but hopefully this helps steer someone else on the right path.

variables:
  light_entity: light.<entity>
  sensor: sensor.<entity>
  sunrise_duration: 30
  start_brightness: 1
  end_brightness: 126
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  manual_time: '08:00:00'
  seconds: '{{int(float(sunrise_duration) * 60)}}'
  end_temperature: 3000
  tick_time: '{{float(seconds) / float(range_brightness)}}'
  check_entity: person.<entity>
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: light.turn_on
        target:
          entity_id: light.<entity>
        data:
          rgb_color:
            - 255
            - 0
            - 0
          brightness: 1
  - 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:
          - delay: 5
          - service: light.turn_on
            data:
              brightness: '{{end_brightness}}'
              transition: '{{seconds}}'
              kelvin: '{{end_temperature}}'
            entity_id: light.<entity>
          - delay: '{{seconds}}'
    default:
      - service: light.turn_on
        data:
          brightness: '{{start_brightness}}'
        entity_id: light.<entity>
  - choose: []
    default:
      - service: light.turn_on
        target:
          entity_id: light.<entity>
        data:
          transition: 300
          brightness: 255
          kelvin: 4000
mode: single
max_exceeded: silent
id: '1637718034053'
alias: Wake-up light alarm with sunrise effect
description: ''

Hi,
Great Blueprint!
Is it possible to use an input_number or a sensor as sunrise_duration? I tried it but it didn’t work.

I was now able to do it with two changes in the blueprint:
line 97:
seconds: '{{float(states(sunrise_duration)) * 60}}'
line 36:

sunrise_duration:
      name: Sunrise duration
      description: The sunrise will start the configured number of minutes before
        the timestamp.
      default: none
      selector:
        entity: {}
1 Like

Together with the changes described here and some additional config is it possible to use the nice Lovelace alarm card from here:


You can easily change the time, mode (Off, Workdays, Weekend, Every Day) and the Duration from the UI.
Steps:

  1. Change the Blueprint according like described here

  2. Install the lightalarm-card like described here

  3. Add the following to you configuration.yaml:

sensor:
  - platform: time_date
    display_options:
      - 'date'
      - 'date_time_iso'
  - platform: template
    sensors:
      lightalarm_1_startdate:
        device_class: timestamp
        value_template: >
          {% if now() == now() %}
          {% endif %}
          {{ today_at(strptime(states("input_datetime.lightalarm_1_time"), "%H:%M:%S").strftime("%H:%M")).isoformat() }}
  - platform: template
    sensors:
      lightalarm_1_condition:
        value_template: >
          {% if is_state('input_select.lightalarm_1_mode', 'Workdays') and now().weekday() in (0,1,2,3,4) %}
            on
          {% elif is_state('input_select.lightalarm_1_mode', 'Weekend') and now().weekday() in (5,6) %}
            on
          {% elif is_state('input_select.lightalarm_1_mode', 'Every Day') %}
            on
          {% else %}
            off
          {% endif %}
      
input_datetime:
  lightalarm_1_time:
    name: Alarm 1 Time
    has_date: false
    has_time: true

input_number:
  lightalarm_1_duration:
    name: Alarm 1 Duration
    unit_of_measurement: min
    min: 1
    max: 60
    step: 1

input_select:
  lightalarm_1_mode:
    name: Alarm 1 Mode
    icon: mdi:alarm-plus
    options:
      - 'Off'
      - 'Workdays'
      - 'Weekend'
      - 'Every Day'
  1. Add the lightalarm-card to your UI and use your created inputs:

  2. Configure the automation:

Hope I haven’t forget anything, let me know if something doesn’t work.

7 Likes

@Sbyx Could you please add a field, for an entity or trigger, that would instantly move the automation to its end phase, if used at any point after the automation has started running?

This would be very useful for people using the phone’s alarm as a trigger.
If you wake up after the automation has started, but before the phone’s alarm has started ringing, you could use this to turn the lights up to full brightness by dismissing the upcoming alarm notification on the phone.

Also, please add more “Additional entities to check before sunrise is triggered” fields.
It would be very useful to be able to check multiple things before triggering, like for example a presence sensor (to make sure you didn’t leave in the middle of the night for some emergency) and a lux sensor (to not trigger the automation, if you were just taking an afternoon nap and the room is otherwise flooded with daylight).

I am not sure if this will help you, but here is what I just got working. input_datetime.alarm is an input datetime with just time, as I didn’t want to have to set the date every day.

      alarm_time_with_date:
        friendly_name: "Alarm Time with Date"
        value_template: "{{states('sensor.date')~' '~states('input_datetime.alarm')}}"
        device_class: timestamp

Hey guys, I hope I didn’t miss this issue in a previous comment (Ctrl-F didn’t help me find anything), but I’m having trouble setting this up with the Next_Alarm sensor.

The script will start running but run into this:


TypeError: forgiving_as_timestamp() takes 1 positional argument but 2 were given

This is my automation config:

variables:
  light_entity: light.alle
  sensor: sensor.sm_g960f_next_alarm
  sunrise_duration: 5
  start_brightness: 154
  end_brightness: 254
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  manual_time: '23:54: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
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: []
  - 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.alle
    default:
      - service: light.turn_on
        data:
          brightness: '{{start_brightness}}'
        entity_id: light.alle
  - 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.alle
                  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.alle
  - choose: []
    default: []
mode: single
max_exceeded: silent
id: '1638830500425'
alias: Wake-up light alarm with sunrise effect
description: ''

And this is my blueprint config:

id: '1638830500425'
alias: Wake-up light alarm with sunrise effect
description: ''
use_blueprint:
  path: sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    pre_sunrise_actions: []
    start_brightness: 154
    sunrise_duration: 5
    min_mired: 0
    manual_time: '23:54:00'
    light_entity: light.alle
    timestamp_sensor: sensor.sm_g960f_next_alarm

as well as my configuration.yaml:


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'

I feel like I’m missing something obvious here or did some stupid mistake. Can someone help me out on this?

1 Like

I’m having some issues with getting this automation to work, and I can’t really find any answers in this thread.

To me it looks like issues with the time checks, where some use sensor.date_time_iso and some use now() which seem to return…different results.

See here:

Could these differences be why nothing is running?

It looks like the missing TZ info on sensor.date_time_iso is what’s causing issues. If I manually add +01:00 to the sensor time, it’s correct.

1 Like

Hey All, so I have everything set up and all other integrations work (mostly as intended). For whatever reason, no matter what I set the start value at on a few different brands of lights the lowest I can get one of them is 54% brightness. The light that I want to use starts at 100% no matter what.

Does anyone have any ideas on what might be causing the high start value?

Soo. One a bit more complicated problem. I have this Automation and I transferred it to a Automation w/o all the blueprint stuff. Now the time stuff is working, like starting 10 Minutes before the alarm and also the pre and post sunrise effect action are getting fired. Now just the brightness is the problem. It starts at 1 brightness then nothing happens(Like not getting brighter) for ~8:45 minutes and then it turns off. Also the trace is not longer available after that. Not sure what’s really happening with that.

###############################################################################
#                _                        _   _
#     /\        | |                      | | (_)
#    /  \  _   _| |_ ___  _ __ ___   __ _| |_ _  ___  _ __  ___
#   / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
#  / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
# /_/    \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
#
###############################################################################

automation:

###############################################################################
# Alarm clock - Light with sunrise
###############################################################################

  - alias: Alarm Clock - Light with sunrise
    variables:
      light_entity: group.schlafzimmer
      sensor: sensor.sm_g998b_next_alarm
      sunrise_duration: 10
      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: 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: device_tracker.sm_g998b
    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: script.toggle
          target:
            entity_id: script.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}}'
            color_temp: '{{start_mired}}'
          entity_id: group.schlafzimmer
      default:
      - service: light.turn_on
        data:
          brightness: '{{start_brightness}}'
        entity_id: group.schlafzimmer
    - 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: group.schlafzimmer
              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: group.schlafzimmer
    - choose: []
      default:
        - service: script.toggle
          target:
            entity_id: script.post_sunrise_actions
    mode: single
    max_exceeded: silent


########################################################################
#  ____                  _           _         
# / ___|    ___   _ __  (_)  _ __   | |_   ___ 
# \___ \   / __| | '__| | | | '_ \  | __| / __|
#  ___) | | (__  | |    | | | |_) | | |_  \__ \
# |____/   \___| |_|    |_| | .__/   \__| |___/
#                           |_|                
########################################################################

script:

  pre_sunrise_actions:
    sequence:

      - service: switch.turn_on
        target:
          entity_id:
          - switch.touch1_flur
          - switch.touch2_schlafzimmer
          - switch.touch4_kuche
          - switch.touch5_wohnzimmer
          - switch.touch6_badezimmer
      - delay: 00:00:10
      - service: light.turn_off
        target:
          entity_id:
          - light.badezimmer_lampe_1
          - light.badezimmer_lampe_2
          - light.flur_lampe_1
          - light.flur_lampe_2
          - light.kuche_lampe_1
          - light.kuche_lampe_2
          - light.wohnzimmer_lampe_1
          - light.wohnzimmer_lampe_2
      - service: input_boolean.turn_on
        entity_id: 
          - input_boolean.alarm_clock_running

  post_sunrise_actions:
    sequence:
      - service: media_player.play_media
        data:
          media_content_id: startmyday
          media_content_type: routine
        target:
          entity_id: media_player.echo_dot_schlafzimmer
      - delay: 00:02:10
      - service: media_player.volume_set
        target:
          entity_id: media_player.uberall
        data:
          volume_level: 0.25
      - service: media_player.play_media
        data:
          media_content_id: Radio Hamburg in überall
          media_content_type: TUNEIN
        target:
          entity_id: media_player.echo_dot_wohnzimmer
      - service: input_boolean.turn_off
        entity_id: 
          - input_boolean.alarm_clock_running

Hi there, hope there’s someone knowledgeable that can help me with this. I’m a day 1 newbie and although borderline illiterate with code, most of the time I can about figure out how to botch together what I need.

I can’t get the automation to activate. When checking the Trace Timeline I’m getting the following message. Does anyone know how to resolve this?

Triggered by the time pattern at 28 December 2021, 18:45:00

Wait for a template to render true

Wait for a template to render true

Stopped because an error was encountered at 28 December 2021, 18:45:00 (runtime: 0.03 seconds)

In 'template' condition: TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'


This is the accompanying message from the error log:

Logger: homeassistant.components.automation.wake_up_light_alarm_with_sunrise_effect
Source: components/automation/__init__.py:512
Integration: Automation (documentation, issues)
First occurred: 18:12:00 (47 occurrences)
Last logged: 18:56:00

Error while executing automation automation.wake_up_light_alarm_with_sunrise_effect: In 'template' condition: TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

Thanks in advance guys!

I have the same issue. Is there any solution for it?

Looks like automations created with this blueprint are throwing some errors:

2021-12-29 15:40:00 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'unavailable' 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. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1

You can try to change all “none”'s in the template to “None”. That’s work for me, but after this change I get the same error as @vitek and @vajdum

Edit: At first use of this blueprint I get this TypeError, but after playing around and type again “none” everything works fine. Maybe you have to type it in, even when the fild contains “none” already?!

The Error “Stopped because only a single execution is allowed at …” seems to be okay, you have to look at the first trace were the automation is “still running” (HA prevent to restart a new run in single-mode, see Automation Modes).

New to HA and wanted to say thanks for this blueprint, it provided a great base for the functionality I wanted.
I’ve added support to add a speaker that slowly increases the volume in combination with the light. This is tested with a Sonos speaker (IKEA Symfonisk). I’m using IKEA Trådfri bulbs so I also had to do some minor changes to how brightness is set. I’ve also added the possibility to lock the color temperature to the set value (incase you want to only increase brightness) and fixed some minor issues with the timestamps.

The issue with the timestamps came from that sensor.time_date_time_iso doesn’t include the timezone information while now() does. So when converted to timestamps, they give different times.

{{states('sensor.date_time_iso')}} = 2022-01-08T20:05:00
{{now()}} = 2022-01-08 20:05:00.004820+01:00

When converted, these should give the same time but

{{as_timestamp(states('sensor.date_time_iso'))}} = 1641672300.0
{{as_timestamp(now())}} = 1641668700.004835

This problem also applies when setting the time manually as

states(''sensor.date'') ~ '' '' ~ manual_time)

also lacks information about the timezone.

Below is my full code with the added functionality and fixes incase it’s useful for someone.
EDIT: I fell victim for the “never post anything until fully tested”. Fixed the code below.

blueprint:
  name: Wake-up light and music alarm with sunrise effect and increasing volume
  description: 'A wake-up light and music alarm with a brightness and color temperature sunrise effect and increasing volume.
    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
    speaker_entity:
      name: Wake-up speaker entity
      description: The speaker to control. Turning it off during the wake-up will keep
        it off.
      selector:
        entity:
          domain: media_player
    music_source:
      name: Sound source
      description: What the speaker should play
      selector:
        select:
          options:
            - Radio Nova
            - Radio SuomiPop
    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.
        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 wake-up 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: {}
    wakeup_duration:
      name: Wake-up duration
      description: The wake-up 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 in percentage
      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: 100.0
          step: 1.0
          mode: slider
    end_brightness:
      name: Maximum brightness in percentage
      description: The brightness will be transitioned from the minimum to the configured
        value.
      default: 100
      selector:
        number:
          min: 5.0
          max: 100.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
    lock_mired:
      name: Lock color temperature
      description: Lock the color temperature to the selected minimum temperature
      default: false
      selector:
        boolean:
    start_volume:
      name: Minimum volume
      description: The volume to start with
      default: 1
      selector:
        number:
          min: 1.0
          max: 100.0
          step: 1.0
          mode: slider
    end_volume:
      name: Maximum volume
      description: The volume will be transitioned from the minimum to the configured
        value.
      default: 20
      selector:
        number:
          min: 5.0
          max: 100.0
          step: 1.0
          mode: slider
    pre_wakeup_actions:
      name: Pre-wakeup actions
      description: Optional actions to run before wake-up starts.
      default: []
      selector:
        action: {}
    post_wakeup_actions:
      name: Post-wakeup actions
      description: Optional actions to run after wake-up ends (around the alarm time).
      default: []
      selector:
        action: {}
variables:
  light_entity: !input 'light_entity'
  speaker_entity: !input 'speaker_entity'
  music_source: !input 'music_source'
  sensor: !input 'timestamp_sensor'
  wakeup_duration: !input 'wakeup_duration'
  start_brightness: !input 'start_brightness'
  end_brightness: !input 'end_brightness'
  range_brightness: '{{float(end_brightness) - float(start_brightness)}}'
  min_mired: !input 'min_mired'
  lock_mired: !input 'lock_mired'
  start_mired: '{{state_attr(light_entity, ''max_mireds'')}}'
  end_mired: '{{[state_attr(light_entity, ''min_mireds'') | int(0), min_mired | int(0)] | max}}'
  range_mired: '{{float(start_mired) - float(end_mired)}}'
  start_volume: !input 'start_volume'
  end_volume: !input 'end_volume'
  range_volume: '{{float(end_volume) - float(start_volume)}}'
  manual_time: !input 'manual_time'
  seconds: '{{float(wakeup_duration) * 60}}'
  tick_time: '{{float(seconds) / float(range_brightness)}}'
  check_entity: !input 'check_entity'
trigger:
- platform: time_pattern
  minutes: '*'
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_datetime() | as_local())
  - as_timestamp(now()) <= float(seconds) and states(check_entity) in [''unknown'', ''on'', ''home'']}}'
- choose: []
  default: !input 'pre_wakeup_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_datetime() | as_local())
    - 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_pct: '{{start_brightness}}'
        color_temp: '{{end_mired + 1 if lock_mired else start_mired}}'
      entity_id: !input 'light_entity'
  default:
  - service: light.turn_on
    data:
      brightness_pct: '{{start_brightness}}'
    entity_id: !input 'light_entity'
- service: media_player.volume_set
  data:
    volume_level: '{{float(start_volume / 100)}}'
    entity_id: !input 'speaker_entity'
- service: media_player.select_source
  data:
    source: !input 'music_source'
    entity_id: !input 'speaker_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_datetime() | as_local())
      - as_timestamp(now()) <= float(seconds)}}'
    sequence:
    - delay: '{{tick_time}}'
    - choose:
      - conditions:
        - '{{0 < state_attr(light_entity, ''brightness'') | int(0) < float(end_brightness) / 100 * 255 | int(0)}}'
        sequence:
        - choose:
          - conditions:
            - '{{state_attr(light_entity, ''min_mireds'') != None}}'
            sequence:
            - service: light.turn_on
              data:
                brightness_pct: '{{float(end_brightness) - ([0, float(range_brightness) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
                  - as_timestamp(now())) / seconds, float(end_brightness)]|sort)[1] | round(0)}}'
                color_temp: '{{end_mired if lock_mired else
                  float(end_mired) + ([0, float(range_mired) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
                  - as_timestamp(now())) / seconds, float(start_mired)]|sort)[1] | round(0)}}'
              entity_id: !input 'light_entity'
          default:
          - service: light.turn_on
            data:
              brightness_pct: '{{float(end_brightness) - ([0, float(range_brightness) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
              - as_timestamp(now())) / seconds, float(end_brightness)]|sort)[1] | round(0)}}'
            entity_id: !input 'light_entity'
    - choose:
      - conditions:
        - '{{0 < state_attr(speaker_entity, ''volume_level'') * 100 | round(0) < float(end_volume) - ([0, float(range_volume) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
          - as_timestamp(now())) / seconds, float(end_volume)]|sort)[1] | round(0) <= float(end_volume)}}'
        sequence:
        - service: media_player.volume_set
          data:
            volume_level: '{{(float(end_volume) - ([0, float(range_volume) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
              - as_timestamp(now())) / seconds, float(end_volume)]|sort)[1]) / 100 | round(2)}}'
          entity_id: !input 'speaker_entity'
- choose: []
  default: !input 'post_wakeup_actions'
mode: single
max_exceeded: silent
2 Likes

Hello, did you manage to fix the issue? I have the exact same problem. If i try to trigger the action manually it stops with the following error.

In 'template' condition: TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

This is my automation config:

variables:
  light_entity: light.0x842e14fffe0ea4b1
  sensor: none
  sunrise_duration: 25
  start_brightness: 1
  end_brightness: 254
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  manual_time: '18:50: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
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: switch.turn_off
        target:
          entity_id: switch.circadian_lighting_circadian_lighting
  - 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.0x842e14fffe0ea4b1
    default:
      - service: light.turn_on
        data:
          brightness: '{{start_brightness}}'
        entity_id: light.0x842e14fffe0ea4b1
  - 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.0x842e14fffe0ea4b1
                  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.0x842e14fffe0ea4b1
  - choose: []
    default:
      - service: mqtt.publish
        data:
          qos: '2'
          topic: shellies/shellyswitch25-BCDDC277A609/roller/0/command/pos
          payload: '100'
      - service: switch.turn_on
        target:
          entity_id: switch.circadian_lighting_circadian_lighting
mode: single
max_exceeded: silent
id: '1641938484000'
alias: Wake-up light alarm with sunrise effect
description: ''

and this is my blueprint config

id: '1641938484000'
alias: Wake-up light alarm with sunrise effect
description: ''
use_blueprint:
  path: sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    light_entity: light.0x842e14fffe0ea4b1
    pre_sunrise_actions:
      - service: switch.turn_off
        target:
          entity_id: switch.circadian_lighting_circadian_lighting
    post_sunrise_actions:
      - service: mqtt.publish
        data:
          qos: '2'
          topic: shellies/shellyswitch25-BCDDC277A609/roller/0/command/pos
          payload: '100'
      - service: switch.turn_on
        target:
          entity_id: switch.circadian_lighting_circadian_lighting
    manual_time: '18:50:00'