Wake-up light alarm with sunrise effect

Got the same problem but with other lights (LIDL Smart lights). Thought my lights did not support the small steps in increase of brightness / color temp. But now I see your post it seems that the lamps are not the problem. Can anybody help? Or is this a known problem? @Sbyx do you recognize this problem?

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.extended_color_light_3
    end_brightness: '254'
    manual_time: '10:02:00'
    start_brightness: '1'
    min_mired: '140'
    sunrise_duration: '30'

@Sbyx @sgobat

Found my own stupid mistake which made the lights go from lowest brightness / color temp to highest brightness / color temp very fast… I set the transition time to be half an hour but then to test it i set the alarm only 1 / 2 minutes in the future. This made the automation execute the light transition in that 1 / 2 minutes.

Just started automating my home haha :smiley: At least I could laugh at my own dumb mistake

I don’t know if it would be possible to add that the input_datetime or manual time at least has to be the current time + transition time.

Seems like @wolfer4004 also has the same issue

1 Like

I’m just curious but will this work with rolling days?

Say that you want the alarm to start at 00:10:00 (just after midnight) with a duration of 25 minutes.
This wait_template implies that it will not work.

0 < as_timestamp(states(sensor) if sensor != ''none'' else states(''sensor.date'')
    ~ '' '' ~ manual_time) - as_timestamp(states(''sensor.date_time_iso'')) <= float(seconds)

Test:

{%- set manual_time = '00:10:00' %}
{%- set seconds = 25*60 %}
{%- set date =  "2021-01-22" %}
{%- set nnow =  strptime("2021-01-22T23:55", "%Y-%m-%dT%H:%M")%}
{{ as_timestamp(date ~ ' ' ~ manual_time) - as_timestamp(nnow) }}
{{ 0 < as_timestamp(date ~ ' ' ~ manual_time) - as_timestamp(nnow) <= float(seconds) }}

Returns False.

This is a suggestion on how to fix it:


{% set date =  "2021-01-22" %}
{% set seconds = 25*60 -%}
Seconds to consider: {{ seconds }}
{% for manual_time in ['23:56:00', '00:10:00'] %}
{%- for iso_date in ["2021-01-22T23:55", "2021-01-22T22:55", ] %}
{%- set nnow =  strptime(iso_date, "%Y-%m-%dT%H:%M")%}
{% set time_diff = (as_timestamp(date ~ ' ' ~ manual_time) - as_timestamp(nnow) ) -%}
Alarm time: '{{manual_time}}', now: {{nnow}}:
Original: {{ 0 < as_timestamp(date ~ ' ' ~ manual_time) - as_timestamp(nnow) <= float(seconds) }},  0 > {{as_timestamp(date ~ ' ' ~ manual_time) - as_timestamp(nnow) }} <= {{ seconds }}
New: {{ (0 < time_diff <= seconds) or  ((24*60*60)-seconds < time_diff*-1 < (24*60*60))
}}, {{ 0 }} < {{time_diff}} <= {{seconds}} or {{(24*60*60)-seconds }} < {{ time_diff*-1}} < {{(24*60*60) }}
{%- endfor %}
{%- endfor %}

Which outputs this:

Seconds to consider: 1500

Alarm time: '23:56:00', now: 2021-01-22 23:55:00:
Original: True,  0 > 60.0 <= 1500
New: True, 0 < 60.0 <= 1500 or 84900 < -60.0 < 86400
Alarm time: '23:56:00', now: 2021-01-22 22:55:00:
Original: False,  0 > 3660.0 <= 1500
New: False, 0 < 3660.0 <= 1500 or 84900 < -3660.0 < 86400
Alarm time: '00:10:00', now: 2021-01-22 23:55:00:
Original: False,  0 > -85500.0 <= 1500
New: True, 0 < -85500.0 <= 1500 or 84900 < 85500.0 < 86400
Alarm time: '00:10:00', now: 2021-01-22 22:55:00:
Original: False,  0 > -81900.0 <= 1500
New: False, 0 < -81900.0 <= 1500 or 84900 < 81900.0 < 86400

Suggestion for change:

- 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'']}}'
#TO
- wait_template: >-
    {% set time_diff = as_timestamp(states(sensor) if sensor != 'none' else 
    states('sensor.date') ~ ' ' ~ manual_time) - as_timestamp(states('sensor.date_time_iso')-%}
    {{(0 < time_diff <= float(seconds) or (86400 - float(seconds) < time_diff|abs < 86400) and 
    states(check_entity) in ['unknown', 'on', 'home']}}

@fredrike you are correct about manual alarm time shortly after midnight. There is also a note about this not working in the help.

1 Like

Hmm… For some reasons I’m unable to get it working :frowning:

alias: Wecker
description: Wake-up light alarm with sunrise effect
use_blueprint:
  path: sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    min_mired: '0'
    light_entity: light.licht_bett_schlafzimmer_felix
    manual_time: '21:15:00'
    sunrise_duration: '5'
    start_brightness: '50'
    end_brightness: '254'
    check_entity: none

The light bulb stays dark. I enabled this automation 5-10 min before the configured time. No log entries, and date_time_iso shows me the correct values.

could you tell us in more detail how you implemented this.
command link is not working

if you create a input boolean, then you only need to add one condition

   - condition: template
     value_template: '{{is_state (' 'input_boolean.wakeup_' '~ [' 'monday' ',' 'tuesday' ',' 'wednesday' ',' 'thursday' ',' 'friday' ',' 'saturday' ',' 'sunday' '] [now (). weekday ()],' 'on' ')}}'

2 alarm entites is no problem ? Or do i need to make 2 automations for this ?

Sure, but if you need a few alarms then it’s more code that you need. From the perspective of the beginner, having this in the blueprint may be easier.

If you’re looking for a Sunrise tracking Sensor that can pull the correct ISO/UTC format to be parsed by as_timestamp in OP’s code, here is one way.

Add this sensor to your configuration.yaml file and manually input it (sensor.nextsunrise) when creating the automation:

sensor:
  - platform: template
    sensors:
      nextsunrise:
        entity_id: sun.sun
        friendly_name: 'Next Sunrise'
        value_template: >
          {{ state_attr('sun.sun', 'next_rising')  }}
        icon_template: mdi:weather-sunset-up

Damn this is exactly what I needed, thank you!!
I had no idea _next_alarm was an option, I love it!

I created a boolean switch to turn it off, I might add a location zone.
My led strip is RGB, as a pre-sunrise action the MQTT publisher will set the colors to 255 and the state to OFF so the automation can take over

Still have to check if manual alarm time is ignored if the timestamp sensor is set, but it seems like it will be

Is there a possibility to set the alarm with my google home hub (Alarm @ my bedside) to use this?

I have some scripts to do it but the setup is painful. However there seems to be a HACS extension here: https://github.com/Drakulix/googlehome
Haven’t reviewed or tested it yet but looks promising at first glance.

Thanks @Sbyx for sharing this blueprint.
I just downloaded it and hope to wake up with a nice sunrise in my room tomorrow morning.

Greetz,
Boris

Edit: typo

Great Job, Thank you for this awesome Blueprint

Hi, i just tested the Blueprint and it works nice. Thanks for this :slight_smile:

But am i right that it is NOT using colors?
Just from warm white to cold white? Is it planned to support color bulbs?

Greetings

Hi
The blueprint works for me, but now i want to add a Feature to my lovelace whit a manual timer anybody knows what i have to add in my ui to change the time setting in this blueprint?

Hi, the blueprint is amazing. Just one Idea. I’m using an WLED LED Strip. Do you think you could add an option to set the effect to the WLED Sunrise effect?

1 Like

Not sure what is necessary to make use of WLED strips. They don’t support setting color using temperature?

@n0nk What would be the expected outcome would be with colors? A lot of color lights also support color temperature which actually starts with very red-ish color (i.e. like an actual sun-rise) and then transitions to daylight white.

@Ctyd Create a date-time helper in HA settings and note down its name (input_datetime.XYZ). It needs to be a helper with BOTH date and time. Set the newly created helper as timestamp sensor in the blueprint automation. Enter manually the name noted down earlier including the input_datetime prefix. Note: You may not be able to select it in the drop down but manual input should work. You can add the input_datetime helper to the UI.

Hey,

i am using a Hue White and Color which works with your blueprint but it does not start red “enough” in my opinion, this is why i asked. I want to get a result like this show in the video --> https://www.youtube.com/watch?v=AYmfEdJmfbE

I am currently trying to add this but i never worked with a blueprint before so this will take some time :slight_smile: I will try to add the colors for the first 30-50% of the brightness and then “switch back” to your solution