Wake-up light alarm with sunrise effect

Hi @TheFes, have you implemented your suggestion? I tried it, but it breaks the automation completely for me. I’m super confused, since I’ve double-checked that now().date gives the same value as states(''sensor.date''), and as_timestamp(now()) is very close to as_timestamp(states(''sensor.date_time_iso'')).

Both replacements result in errors. If I replace only as_timestamp(states(''sensor.date_time_iso'')), I get the following error:
sunrise test: Error executing script. Error for wait_template at pos 2: In 'template' condition: AttributeError: 'datetime.datetime' object has no attribute 'lower'

If I replace states(''sensor.date'') or both, I get:
sunrise test: Error executing script. Error for wait_template at pos 2: In 'template' condition: TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

I wonder if something needs to be typecasted to a different form. Any ideas?

Sorry, no, not properly.
I guess I better not posted it, as I don’t use this myself, I just stumbled upon it.

Might be better to leave it as it is.

Is there a way that I can debug each step of the blueprint? The best way where a file for each day which can be checked with diff.

I use these from Monday to Thursday to wake me up and I works fine, except on Tuesday.I use only one setting with the template with 1- 4 isoweekday. Why the behavior on Tuesday is different is not understandable for me, so I would look to catch this.

I have the same issue as aaljovic with

How do we fix this???

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

1 Like

Same here!
Let’s try to find a common point in setups with and without the issue.

version: core-2022.2.2
installation_type: Home Assistant Container
dev: false
hassio: false
docker: true
user: root
virtualenv: false
python_version: 3.9.7
os_name: Linux
os_version: 5.4.0-1047-raspi
arch: aarch64
timezone: Europe/Lisbon

Same here, also got this error message:

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

Then I figured out just RTFM !!! This fixed the error’s. Will test the automation now.

Cheers, Daniel

After I testet the automation now, I can say it works as expected! Thanks to @Sbyx

As far as I figured out, you have to add the following to ur configuration.yml:

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

After that, restart your HA. Like ServerControl > restart

I have an odd issue with this blueprint. When the automation triggers, after a min, my lights trigger on and then immediately off.

I’m using the latest code on github, with the following settings:

- alias: wake-up-light
    use_blueprint:
      path: sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
      input:
        light_entity: light.bedroom_lights
        manual_time: '14:15:00'
        sunrise_duration: '10'

I’m not really sure how to troubleshoot this. Any tips would be appreciated.

1 Like

Thoughts on what could be causing this automation to skip all the way to the end in 7 seconds? Trying this on a new HA instance and testing is going poorly. I have the lights setup through local tuya instead of a cloud tuya app if that makes a difference.

In my case (Hassio & supervisor 2022.3.5) automation works depending on the day. The error is 100% the time comparison mentioned by @Caze but I have tried to adapt his code to the original version with no luck.

Im a programmer myself, but its being hard to start because I dont even know how to properly debug this.
Can someone tell me where could I find information about the operators ~, |… or the syntaxis? Its complicated to decode what this exactly does.

'{{0 < as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())

I mean, I guess you get the information from the sensor or from your manual time and convert it using as_timestaps. Ok. But what ~ ‘’ ‘’ ~ means for example??

Thanks in advance!

The ~ is basicly a string concat, so the
states(''sensor.date'') ~ '' '' ~ manual_time
is the same as
date + " " + manual_time
so you have a string which then gets converted to a datetime and then local time with timezone.

Sorry to bother you again.

So the beggining is:

if sensor is != none:
as_timestamp(states(sensor))
else:
as_timestamp(states(sensor.date) + " " + manual_time)

which means first take the alarm time (manual or by a sensor) and include the date.
Then you have:

as_timestamp(states(''sensor.date_time_iso''))

which means take thet date time now.

So you do alarm_time - data_time_now and check if its less or equal to the amount of time the script should be running (float(seconds)) and also check if the other condition.

Questions:

  1. when the first part ( 0 < …) gets evaluated?
  2. Assuming | means OR why have you added | as_datetime() | as_local() in your script?
  3. In case I want to check the output of the ‘‘as_timestamp’’ which is the correct way to debug/print and check it?

Thanks a lot in advance!

Thanks for this blueprint. It works as described! Ik would like to swap out the manual time element for aan date/time helper. How would i go about that?

nice one. exactly what i need. is there any chance to use spotify as a source?
want to play a specific playlist.

read the help text beside the sensor inputs.

Alarm timestamp sensor
Sensor with timestamp of next alarm with device_class: timestamp (set to ‘none’ for manual alarm time)

and

Manual alarm time
Time to trigger alarm every day if timestamp sensor is not set.

Hey,
it stopped working a few days ago. Can’t really see whats the problem. I dont understand the problem.

My config:

id: '1608150624793'
alias: '[Schlafzimmer][Light] Sonnenaufgang'
description: ''
use_blueprint:
  path: Sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    max_brightness: '100'
    light_entity: light.gruppe_schlafzimmer
    min_mired: 200
    manual_time: '08:36:00'
    start_brightness: 11
    end_brightness: 255
    sunrise_duration: 25
    timestamp_sensor: none
    pre_sunrise_actions:
      - service: automation.turn_off
        target:
          entity_id: automation.schlafzimmer_light_auto
        data: {}
    post_sunrise_actions:
      - service: automation.turn_on
        target:
          entity_id: automation.schlafzimmer_light_auto
        data: {}
    check_entity: binary_sensor.workday_sensor

It seems the template here returns false, but why?

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']}}

1 Like

I seem to be having the same issue. Mine came up about the same time as the April update to HA. Please post if you find a solution.

@Sbyx nice blueprint. runs great. i want to have a single automation which should run primarly on weekdays but if i set a trigger to on it should also run on weekends.

i already have a trigger and i am trying to combine this with now().isoweekday() in pre sunrise actions.

is something like this possible? are these actions “or” or “and” combined?

    pre_sunrise_actions:
      - wait_template: '{{ 1 <= now().isoweekday() <= 5 }}'
      - wait_template: >-
          {{ 6 <= now().isoweekday() <= 7 and is_state("input_boolean.alarm_clock_weekend", "on") }}

@Sbyx very good work with this blueprint!
I just used it for a couple of days and I found something :slight_smile:
I am using this blueprint based on the next_alarm timestamp from the Android companion App.

Initially I found this approach very clever (using the phone configured alarm) until I found that every calendar notification (events, etc) also change / update the next_alarm timestamp on the phone and immediately on Home Assistant.
This means that I had to disable this automation because the light and speaker I turn on with this, were being triggered every now and then during the day… :frowning:

Is it possible to filter only the next_alarm configured in the phone clock and not consider calendar notifications or other sources that might change next_alarm ?

Note: I am aware of

Additional entity to check before the sunrise is triggered

but I would need to over engineer it to prevent calendar reminders (triggered on phone) from waking me up in the middle of the night/weekend/etc…
Do you have any hint or suggestion that I’m not considering?

In the Companion app settings, in the next alarm sensor configuration, set which package(s) you want the next alarm sensor to use as source.