Simple light wake-up alarm with parabolic sunrise effect

Just tested here. Works like a charm! I’m using Philips Hue Lights running on zigbee2mqtt.

1 Like

Thanks for this script!
I was using the other popular one but I’m willing to give this one a try since it is supposed to be more optimized.

Yet, I’m still relatively new to Home Assistant and I really don’t understand anything yaml based.

Basically, instead of a fixed hour, I would like to use alarms set in my Google Home device I integrated in HA. That device’s next alarm is shown in entity: sensor.lenovo_smart_clock_alarms

So, as the trigger, I would like it to be : sensor.lenovo_smart_clock_alarms - alarm_length variable

I searched forums and tried what is below but it does not work.

trigger:
  - platform: template
    value_template: "{{ now() >= states('sensor.lenovo_smart_clock_alarms') | as_datetime - timedelta(minutes=alarm_length) }}"

How can I reference alarm_length in the yaml automation code so that it works?
Thank you

BTW: there is a typo in your thread title. That could hinder the possibility of finding this thread later on.

This would be great, but it errors on the check

state_attr(target_light, 'color_temp') <= min_mireds

My lights aren’t reporting the color_temp - it’s null, so it hits an error. Does anyone have a brilliant idea for converting the value to HS in-line like this? I have RGB, HS, and xy color. No kelvin or mired.

Maybe I should just buy the hue hub… I’ve spent the whole weekend trying to get a solution that works; the complicated blueprint referenced only checks for one variable for conditions and spams the logs, I can’t stand it.

They also don’t support transition, which is the easy way to do all this.

I have white only bulbs and replacing the condition

            - condition: template
              value_template: "{{ state_attr(target_light, 'color_temp') <= min_mireds }}"

with

            - condition: and
              conditions:
                - condition: template
                  value_template: "{{ state_attr(target_light, 'color_temp') != None }}"
                - condition: template
                  value_template: "{{ state_attr(target_light, 'color_temp') <= min_mireds }}"

did the trick for me.

2 Likes

Are you still folowing this thread ?

I’ve create a blueprint for this automation. The script in the first post will still need to be copied to your instance manually first, then specified when you create the automation from the blueprint below.

The blueprint is basically the same as the automation in the first post but configured via automation GUI.

It assumes you’re using the Workday Integration to determine whether it will be triggered on a particular day. You could use any binary_sensor to replace the Workday binary_sensor if you do not wish to use the Workday Integration.

You’ll also need an input_datetime helper to use to trigger the start time. Create one with time only.

Blueprint on Github for import

blueprint:
  name: Parabolic Alarm Automation
  description: Turn a light on based on detected motion
  domain: automation
  input:
    alarm_start_time:
      name: Start Time
      description: Datetime helper for alarm to start. Use time only and Workday sensor to determine what days to run.
      selector:
        entity:
          filter:
            - domain: input_datetime
    workday_sensor:
      name: Workday Sensor
      description: Binary Sensor for determining it it should run. Typically  from Workday Integratoin
      selector:
        entity:
          filter:
            - domain: binary_sensor
    alarm_script:
      name: Script to trigger
      description: Script to trigger
      selector:
        entity:
          filter:
            - domain: script
    target_light:
      name: Lights
      description: The light(s) with Mireds
      selector:
        entity:
          filter:
            - domain: light
    light_timeout:
      name: Timeout
      description: Light will turn off after this time on last run
      default: 10
      selector:
        number:
          min: 1
          max: 60
    steps_per_minute:
      name: Steps per minute for all runs
      description: Used for configuring percentage of each step for brightness and color temperature
      default: 12
      selector:
        number:
          min: 1
          max: 60

    min_mireds_1:
      description: Minimum mireds value (coldest) for 1st run
      selector:
        color_temp:
      default: 375
      name: Min Mireds 1
    max_mireds_1:
      description: >-
        Maximum mireds value (warmest) for 1st run
      selector:
        color_temp:
      default: 400
      name: Max Mireds 1
    max_brightness_1:
      name: Maximum Brightness 1
      selector:
        number:
          min: 1
          max: 100
      default: 10
    alarm_length_1:
      name: Alarm Length 1
      description: >-
        This is the start to finish time for the first run
      selector:
        number:
          min: 1
          max: 60
      default: 10

    min_mireds_2:
      description: Minimum mireds value (coldest) for 1st run
      selector:
        color_temp:
      default: 300
      name: Min Mireds 1
    max_mireds_2:
      description: >-
        Maximum mireds value (warmest) for 1st run
      selector:
        color_temp:
      default: 400
      name: Max Mireds 1
    max_brightness_2:
      name: Maximum Brightness 1
      selector:
        number:
          min: 1
          max: 100
      default: 50
    alarm_length_2:
      name: Alarm length 2
      description: >-
        This is the start to finish time for the second run
      selector:
        number:
          min: 1
          max: 60
      default: 10

    min_mireds_3:
      description: Minimum mireds value (coldest) for 1st run
      selector:
        color_temp:
      default: 160
      name: Min Mireds 1
    max_mireds_3:
      description: >-
        Maximum mireds value (warmest) for 1st run
      selector:
        color_temp:
      default: 400
      name: Max Mireds 1
    max_brightness_3:
      name: Maximum Brightness 1
      selector:
        number:
          min: 1
          max: 100
      default: 100
    alarm_length_3:
      name: Alarm Lenght 3
      description: >-
        This is the start to finish time for the third run
      selector:
        number:
          min: 1
          max: 60
      default: 5

trigger:
  - platform: time
    at: !input alarm_start_time

condition:
  - condition: state
    entity_id: !input workday_sensor
    state: "on"

action:
  - service: !input alarm_script
    data:
      min_mireds: !input min_mireds_1
      max_mireds_selector: !input max_mireds_1
      max_brightness_pct: !input max_brightness_1
      alarm_length: !input alarm_length_1
      steps_per_minute: !input steps_per_minute
      light_timeout: 0
      target_light: !input target_light
  - if:
      - condition: state
        state: "on"
        entity_id: !input target_light
    then:
      - service: !input alarm_script
        data:
          min_mireds: !input min_mireds_2
          max_mireds_selector: !input max_mireds_2
          max_brightness_pct: !input max_brightness_2
          alarm_length: !input alarm_length_2
          steps_per_minute: !input steps_per_minute
          light_timeout: 0
          target_light: !input target_light
  - if:
      - condition: state
        state: "on"
        entity_id: !input target_light
    then:
      - service: !input alarm_script
        data:
          min_mireds: !input min_mireds_3
          max_mireds_selector: !input max_mireds_3
          max_brightness_pct: !input max_brightness_3
          alarm_length: !input alarm_length_3
          steps_per_minute: !input steps_per_minute
          light_timeout: !input light_timeout
          target_light: !input target_light
mode: parallel
max: 10

First post here and I don’t really have the cred to post a video but I don’t think this is behaving as intended and whilst a video would be the best way to demonstrate this I’ll pate what I put into Claude to see if it could help but it couldn’t really.

The light flicks on and pretty quickly (i.e. within a second or 2) transitions / gets to a high brightness then resets to a low brightness and transitions / gets up to some other target brightness and then resets to dimmer yet then transitions / gets up to some other brightness that was different to before and then just loops like this continuously in this triad of low to max with different lows and different maxes.

Not sure what I did wrong but I was hoping for a gradual slope from 0% up to my target brightness over the course of several minutes not < 5 seconds. Would love to know what I’ve done wrong. For reference, I’m using an Ikea zigbee RGB light

What bulb are you using? Does it support mireds?

Any change you can modify that to gather the “next alarm” info from a sensor?

I don’t always wake up at the same time so I just set my Alexa every night. I know it shares this information with HA so it’s possible to do so, I just don’t have the technical skill to do it.

Check out the first post and link to the blueprint. That one will link to your phone alarm.

What blueprint are you referring to? The original one that inspired your work or your own blueprint?

I’m in same position than @Dumonster, as I would like that the alarm time (and thus also day) is whatever is set in Google Assistant and that is read by Home Assistant with Google Home integration.

yes, the original post

So for some reason this stopped working between when I disabled the automation created by the blueprint at the end of the school year and now. I’ve used the opportunity to refactor both the blueprint and the script so if upgrading you will need to update the script as well.

I’ve switch to using Kelvin as the color temperature and removed some redundant inputs.

Both the script and the blueprint can be found in the github repo.

1 Like

Thanks for the perfect timing, I’ve been wanting to try this for a while and finally made time for it today. I’ve followed your instructions and will hopefully wake up to the ‘sunrise’ tomorrow with my first ever HA automation.

Thanks for giving us an alternative to the well known and highly used “Wake-up light alarm with sunrise effect”. I’ve had some issues with that blueprint and decided to use yours. So far so good ! This morning it worked like a charm. :slight_smile:

Thanks !

This seems to be getting some attention so I updated it to make installation easier. Both the script and automation are now blueprints. See the original post for details.

I liked the script with the fields better :slight_smile:
And do multiple lights still work?

I get this error: TypeError: unhashable type: ‘list’

I didn’t consider multiple lights as an input. However, you can probably create a light group and use that in the script/automation to control multiple lights.

This is so awesome thank you.

Im going to create a “Sunrise” light group and test that out.

Hello everyone,
I think I’ve understood the automation/script so far now. The start time has to be set before the actual alarm. And as far before as the sum of the 3 alarm lengths? Right? I have an iPhone and now have a shortcut that sends me the next alarm in HA (so dynamic). Now I would have to manipulate this time to use it in the automation. Wouldn’t it be possible to calculate the start time for sunrise? In other words, 6:00 alarm, so phase 1 10min + phase 2 10min + phase 3 5min = 25min, so the start time would be at 5:35. Wouldn’t that be easier in general? Or have I misunderstood something?

And thank you very much for the great work so far :slight_smile: