Wake-up light alarm with sunrise effect

Spot on @terryhonn :grinning: !

Thank you very much.
The amount of sensor possibilities is utterly huge to select the one wanted, but one can set up an alarm in the clock and check the Package that triggered it below in the alarm sensor in the companion app.
With this info, it’s easy to select just that one in the Allow List of the Alarm Sensor.
In case it helps anyone else, in my case this is [com.google.android.deskclock].

1 Like

I have the same problem as 00chrisellis and it-guy92 it seems.
simple config, but it’s never triggered. running latest stable home assistant.

Hi there, I am having an issue importing this blueprint. The Logs display this as the error

File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 56, in <lambda>
    lambda dumper, value: represent_odict(dumper, "tag:yaml.org,2002:map", value),
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 40, in represent_odict
    node_value = dumper.represent_data(item_value)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 58, in represent_data
    node = self.yaml_representers[None](self, data)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 231, in represent_undefined
    raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', <NumberSelectorMode.SLIDER: 'slider'>)

(Sorry I am kinda new to home assistant, so any help will be much appreciated)

Attempting to import the blueprint from Gist results in a “unknown error” using HA 2022.5.0

Here’s the error log:


Logger: homeassistant.components.websocket_api.http.connection
Source: util/yaml/dumper.py:40 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 7:39:45 PM (1 occurrences) 
Last logged: 7:39:45 PM

[139991711883520] Error handling message: Unknown error (unknown_error)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/blueprint/websocket_api.py", line 125, in ws_save_blueprint
    await domain_blueprints[domain].async_add_blueprint(blueprint, path)
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 327, in async_add_blueprint
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 318, in _create_file
    path.write_text(blueprint.yaml(), encoding="utf-8")
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 107, in yaml
    return yaml.dump(self.data)
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 13, in dump
    return yaml.safe_dump(
  File "/usr/local/lib/python3.9/site-packages/yaml/__init__.py", line 269, in safe_dump
    return dump_all([data], stream, Dumper=SafeDumper, **kwds)
  File "/usr/local/lib/python3.9/site-packages/yaml/__init__.py", line 241, in dump_all
    dumper.represent(data)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 56, in <lambda>
    lambda dumper, value: represent_odict(dumper, "tag:yaml.org,2002:map", value),
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 40, in represent_odict
    node_value = dumper.represent_data(item_value)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 56, in <lambda>
    lambda dumper, value: represent_odict(dumper, "tag:yaml.org,2002:map", value),
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 40, in represent_odict
    node_value = dumper.represent_data(item_value)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 56, in <lambda>
    lambda dumper, value: represent_odict(dumper, "tag:yaml.org,2002:map", value),
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 40, in represent_odict
    node_value = dumper.represent_data(item_value)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 56, in <lambda>
    lambda dumper, value: represent_odict(dumper, "tag:yaml.org,2002:map", value),
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 40, in represent_odict
    node_value = dumper.represent_data(item_value)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 56, in <lambda>
    lambda dumper, value: represent_odict(dumper, "tag:yaml.org,2002:map", value),
  File "/usr/src/homeassistant/homeassistant/util/yaml/dumper.py", line 40, in represent_odict
    node_value = dumper.represent_data(item_value)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 58, in represent_data
    node = self.yaml_representers[None](self, data)
  File "/usr/local/lib/python3.9/site-packages/yaml/representer.py", line 231, in represent_undefined
    raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', <NumberSelectorMode.SLIDER: 'slider'>)

I deleted my automation, re-created it, changed it to work on one light instead of a group, nothing worked. I ended up changing it to a different light and it still didn’t work. I ended up using Watchman to clean up some stuff in other automations and dashboards. This may be coincidental, but this is the second morning in a row that it has worked correctly. I am always making little tweaks to HA though, so who know what the fix was. I need to set it back to work on the bedroom group of lights though, even though it is now almost light out when I am supposed to get out of bed. I will post again if I break it.

Hello! Have you checked what is the state of your binary_sensor.workday_sensor when the automation should’ve run?

I was configuring a “gating” sensor to enable/disable this automation based on a series of conditions, but my output was Boolean (True/False), and this blueprint expects ‘on’ or ‘home’ as signals to trigger the automation. I went the easy route and modified the Blueprint to also allow ‘True’ as a condition to run (there’s two places to change, search for ‘home’ and you’ll find them)

I’ve recently started using this blueprint (which is fantastic btw, thank you @Sbyx ) and have been wondering the same thing. My bedside lights are LIFX bulbs and the coolest colour is very, very blue, well beyond “cool white” - would love to be able to set a maximum colour temp and keep them more in the orange range in the morning.

2 Likes

Please make this blueprint with an option to begin at the colour red! my lights don’t handle low light values for some reason. If I turn the light on to 1% its a very steep transition from 0%… but if I could start at red, then work to orange and yellow, before then going through the whites and raising the brightness value. it would be a lot smoother. other than that this blueprint works flawlessly. probably one of the best prints for beginners, thank you!

1 Like

How to cancel a running alarm?
I suppose I could disable the check boolean. But then I need to re-enable it for next night…

Also, can I use a input_datetime for alarm time? I suppose a template would do that. I’m not sure when it’s evaluated. I suppose I could figure this one out…

I’d like to be able to use a boolean sensor for check_entity.
I’ve tried editing the file in my HA, but have not bee successful in making this happen.

I tried adding several items to the “in” list (below) to lines 116 and 124, from:
...and states(check_entity) in [''unknown'', ''on'', ''home'']}}'

to

...and states(check_entity) in [''unknown'', ''on'', ''home'', *stuff i've tried*]}}'

but have had no success.
I’ve restarted HA after each change.

stuff I’ve tried:
- true
- ‘true’
- True
- ‘True’ ← this one worked
- 1
- ‘1’
- Boolean(true)

Edit:
I solved the problem by changing the output of my sensor match the criteria of the blueprint -a solution I hadn’t considered initially.

Second Edit:
Apparently I didn’t actually check ‘True’ very carefully because it’s working now.

This is a great blueprint. When implementing, there are two functions I am missing and I don’t see how to add myself within this blueprint. Maybe they are nice enough to add:

  • The option to turn the light “off” again after “x” minutes after the alarm time. [In case you forget, or in case of the day you just forgot to turn off the alarm and don’t want the light to be on all day)
  • The option to add another condition. I am already using the workday check, but I also have implemented a manual helper which states my holidays. Would be great if I could use this extra condition to check whether I have a day off or am away because of holidays.

Keep up the good work!

Iam a bit new to the whole home assistant,but can i edit this blueprint in some way.
As stated above i also would love to add more conditions to this blueprint.and on a side note does anybody have a good solition to fade in music using spotify and some speaker to trigger along side this awesome blueprint?

I’ve been using this blueprint successfully for months in 2 separate rooms.
Now i’ve added a Tile to my daughter’s bag so HA knows when she is staying with me, i only want the sunrise in her room to run when she’s present. Unfortunately the ‘additional entity’ check doesn’t seem to work.
Is there any way to fix this, or transfer it out into an automation so i can use the standard presence check (which does work)?

It depends on what your Tile reports, it needs to be on or home
I created a template_sensor based on recommendations earlier in the thread to do just this:

      wakeup_alarm_enabled:
        value_template: >
          {% set unused = now() %}
          {%- if states('binary_sensor.workday_sensor') == 'on' and states('zone.home') | int > 0 %}
            on
          {%- else %}
            off
          {% endif %}

In my case it check for people being home, but you can change the validation to whatever you need

I think it reports ‘Home’ and ‘away’ notice the case.
And i think the blueprint only wants ‘home’ and ‘not_home’

I’m testing using a separate automation to check for the tile presence in the evening and then turn the sunrise automation on and off

You could use a template sensor and use any value you want, e.g.

      wakeup_alarm_enabled:
        value_template: >
          {% set unused = now() %}
          {%- if states('device_tracker.kids_backpack') == 'Home' %}
            on
          {%- else %}
            off
          {% endif %}

I’m looking at my Tile devices and they correctly show home and not_home

This is the only information i can see regarding the Tile entity.
Am i missing something?

I also have some IKEA bulbs. Could you maybe post a variant without sound? I’d really like to use your variant but I’m kind a too stupid to get it running without sound :frowning:

I didn’t want to filter the alarms from other apps, so I just created a template sensor and filter clock alarm there:

template:
  - sensor:
      - name: morning_alarm
        device_class: timestamp
        state: >
            {% if is_state_attr('sensor.samsung_s22_next_alarm','Package','com.sec.android.app.clockpackage') %}
                {{(state_attr('sensor.samsung_s22_next_alarm','Time in Milliseconds') /1000) | as_datetime}}
            {%endif%}

It works, however, now I’m trying to figure out how to filter only morning alarms (I usually have alarms in the afternoon as well). Any ideas?

P.S I’ve noticed that if you have several alarms, lights start behaving kind of crazy and increasing and decreasing brightness.

Hello everybody,

i am still trying to get this automation to work.

The automation started but then i got the following error:

Stopped because only a single execution is allowed at 31. Juli 2022 um 01:46:00 (runtime: 0.00 seconds)

The automation starts with the configured time and the light turned on.

I use hue bulbs over deconz/phoscon.

Home Assistant Versions are:

Home Assistant 2022.7.7
Supervisor 2022.07.0
Operating System 8.4
Frontend 20220707.1 - latest

Eventually somebody has an idea for a solution.

Best regards

DiBa

Here is my automation config:

variables:
  light_entity: light.wohnzimmer_deckenlicht_1
  sensor: none
  sunrise_duration: 10
  start_brightness: 1
  end_brightness: 100
  range_brightness: '{{float(end_brightness)-float(start_brightness)}}'
  manual_time: '01:55: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.wohnzimmer_deckenlicht_1
    default:
      - service: light.turn_on
        data:
          brightness: '{{start_brightness}}'
        entity_id: light.wohnzimmer_deckenlicht_1
  - 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.wohnzimmer_deckenlicht_1
                  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.wohnzimmer_deckenlicht_1
  - choose: []
    default: []
mode: single
max_exceeded: silent
id: '1659224424147'
alias: Wake-up light alarm with sunrise effect
description: ''

Here is my blueprint config:

id: '1659224424147'
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.wohnzimmer_deckenlicht_1
    manual_time: '01:55:00'
    sunrise_duration: 10
    end_brightness: 100

Here are the informations from the trace:

{
  "trace": {
    "last_step": "trigger/0",
    "run_id": "e2709011996d21bea3ed236dce43164c",
    "state": "stopped",
    "script_execution": "failed_single",
    "timestamp": {
      "start": "2022-07-30T23:46:00.015774+00:00",
      "finish": "2022-07-30T23:46:00.018836+00:00"
    },
    "domain": "automation",
    "item_id": "1659224424147",
    "trigger": "time pattern",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-07-30T23:46:00.018682+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.wake_up_light_alarm_with_sunrise_effect",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-07-30T23:45:00.009237+00:00",
                "mode": "single",
                "current": 1,
                "id": "1659224424147",
                "friendly_name": "Wake-up light alarm with sunrise effect"
              },
              "last_changed": "2022-07-30T23:44:18.732511+00:00",
              "last_updated": "2022-07-30T23:45:00.009409+00:00",
              "context": {
                "id": "01G98QZD36HZAYNJAVQCNRPHSB",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "time_pattern",
              "now": "2022-07-31T01:46:00.005615+02:00",
              "description": "time pattern"
            },
            "light_entity": "light.wohnzimmer_deckenlicht_1",
            "sensor": "none",
            "sunrise_duration": 10,
            "start_brightness": 1,
            "end_brightness": 100,
            "range_brightness": 99,
            "manual_time": "01:55:00",
            "seconds": 600,
            "min_mired": 0,
            "start_mired": null,
            "end_mired": 0,
            "tick_time": 6.0606060606060606,
            "check_entity": "none"
          }
        }
      ]
    },
    "config": {
      "variables": {
        "light_entity": "light.wohnzimmer_deckenlicht_1",
        "sensor": "none",
        "sunrise_duration": 10,
        "start_brightness": 1,
        "end_brightness": 100,
        "range_brightness": "{{float(end_brightness)-float(start_brightness)}}",
        "manual_time": "01:55: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.wohnzimmer_deckenlicht_1"
                }
              ]
            }
          ],
          "default": [
            {
              "service": "light.turn_on",
              "data": {
                "brightness": "{{start_brightness}}"
              },
              "entity_id": "light.wohnzimmer_deckenlicht_1"
            }
          ]
        },
        {
          "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.wohnzimmer_deckenlicht_1"
                              }
                            ]
                          }
                        ],
                        "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.wohnzimmer_deckenlicht_1"
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          }
        },
        {
          "choose": [],
          "default": []
        }
      ],
      "mode": "single",
      "max_exceeded": "silent",
      "id": "1659224424147",
      "alias": "Wake-up light alarm with sunrise effect",
      "description": ""
    },
    "blueprint_inputs": {
      "id": "1659224424147",
      "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.wohnzimmer_deckenlicht_1",
          "manual_time": "01:55:00",
          "sunrise_duration": 10,
          "end_brightness": 100
        }
      }
    },
    "context": {
      "id": "01G98R17PFM7Q5XSWSN43MGSMP",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": []
}