A Wake-Up Light is in my experience a better way to wake up, and I have earlier used a simple time trigger to achieve it.
This is of course not ideal because I don’t always want to get up at the same time, or even get waked up at all (vacations, different working hours ect). I also don’t want to set another duplicate alarm just for the lights.
What I could have done is made a fully Home-Assistant based alarm that I set in Home-Assistant, but I don’t trust Home-Assistant and my home server enough to have my alarm dependent on it.
That’s why I’ve been working on this project lately. The goal was a system that is fully automatic with no need of user input expect for the normal android alarm I use anyway.
This is the solution I have come up with, and it works perfect in my setup.
Home-Assistant Configuration
In Home-Assistant I made these changes in my configuration.yaml file.
The input_boolean is to store if the alarm enabled or not on my Android phone, I will use this as a condition in the automation so the lights don’t turn on when alarm is disabled.
input_boolean:
flemming_phone_alarm_set:
name: Flemmings telefon alarm
The input_datetime is to store the time and date when my next alarm are set.
input_datetime:
flemming_phone_next_alarm_date_and_time:
name: Flemmings neste alarm
has_date: true
has_time: true
The time_date sensor is required to compare alarm time/date and the current time/date in the automation.
More information about this here: https://www.home-assistant.io/integrations/time_date/
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
Tasker Configuration
A Task To Call Home-Assistant
From other projects I have already set up a way to communicate with the Home-Assistant API, so I will not go in detail here. But a complete step-by-step guide can be read here:
🡆 How to use Tasker with Home-Assistant 🡄
This task can also be downloaded at TaskerNet by following this link:
https://taskernet.com/shares/?user=AS35m8nnNwr4R%2FLkT8mMxioo6MpBcI6C2gxgpSKHJjKSqEwaxdvKcFHhOI%2FFaRHqiJ7Xh7M%3D&id=Task%3AP%C3%A5kall+Home-Assistant (but read the above article to understand how it works)
A Task to send values to Home-Assistant
The first thing was to download the AutoAlarm plugin for Tasker from Google Play.
This plugin create and maintain variables with information about the next alarm set. If multiple alarms are set the values represented in variables are the values for the next one to ring.
In this task I make use of these variables:
- %year – The year next alarm will ring (eg 2019)
- %month – The month next alarm will ring (eg 11)
- %day – The day of the month next alarm will ring (eg 7)
- %hour – The hour of the day next alarm will ring (eg 18)
- %minute – The minute in the hour next alarm will ring (eg 30)
In the above example the alarm will ring 18:30, 7. November 2019.
If no alarm is activated these variables will not hold any values at all.
So I made this task:
This is how it works:
- First I added AutoAlarm as a Plugin in the start, no configuration needed, it just have to be there to populate the variables.
- If the %year variable is a number it means it has a value, and that means the alarm are activated. If that is the case the following will happen:
- The input_datetime.flemming_phone_next_alarm_date_and_time entity will be updated with values from Auto-Alarm.
par1:/api/services/input_datetime/set_datetime
par2:{"entity_id":"input_datetime.flemming_phone_next_alarm_date_and_time","date":"%year-%month-%day","time":"%hour:%minute:00"}
- The input_boolean.flemming_phone_alarm_set entity will be set to “on” to indicate that the alarm is activated.
par1:/api/services/input_boolean/turn_on
par2:{"entity_id":"input_boolean.flemming_phone_alarm_set"}
- The input_datetime.flemming_phone_next_alarm_date_and_time entity will be updated with values from Auto-Alarm.
- Else If the %year is not a number, then it in this case means the alarm is deactivated.
If that is the case the following will happen:- The input_boolean.flemming_phone_alarm_set entity will be set to “off” to indicate that the alarm is deactivated.
par1:/api/services/input_boolean/turn_off
par2:{"entity_id":"input_boolean.flemming_phone_alarm_set"}
- The input_boolean.flemming_phone_alarm_set entity will be set to “off” to indicate that the alarm is deactivated.
Description generated by Tasker:
Mobil Alarm Til Home-Assistant (9) A1: AutoAlarm [ Configuration:NOTE: This will not work correctly if the 'Relible Alarms' option is enabled in Tasker. No extra configuration needed Timeout (Seconds):5 ] A2: If [ %year ~R [0-9]+ ] A3: Perform Task [ Name:Påkall Home-Assistant Priority:%priority Parameter 1 (%par1):/api/services/input_datetime/set_datetime Parameter 2 (%par2):{"entity_id":"input_datetime.flemming_phone_next_alarm_date_and_time","date":"%year-%month-%day","time":"%hour:%minute:00"} Return Value Variable: Stop:Off ] A4: Perform Task [ Name:Påkall Home-Assistant Priority:%priority Parameter 1 (%par1):/api/services/input_boolean/turn_on Parameter 2 (%par2):{"entity_id":"input_boolean.flemming_phone_alarm_set"} Return Value Variable: Stop:Off ] A5: Else If [ %year !~R [0-9]+ ] A6: Perform Task [ Name:Påkall Home-Assistant Priority:%priority Parameter 1 (%par1):/api/services/input_boolean/turn_off Parameter 2 (%par2):{"entity_id":"input_boolean.flemming_phone_alarm_set"} Return Value Variable: Stop:Off ]
I have uploaded my above task on TaskerNet so it can be downloaded and re-used.
https://taskernet.com/shares/?user=AS35m8nnNwr4R%2FLkT8mMxioo6MpBcI6C2gxgpSKHJjKSqEwaxdvKcFHhOI%2FFaRHqiJ7Xh7M%3D&id=Task%3AMobil+Alarm+Til+Home-Assistant
A profile to trigger
To the above task I have create two profiles to trigger it.
The first one will trigger by application, when the Clock app is opened, and when it is exited.
The other one will trigger every by time every 30 minutes.
I really just ned one of these, but the first one will not trigger if I open the clock app, configure alarm, and then don’t exit the app. So here the other profile acts as a backup.
However, I could have just used the last one, but then I will miss out of immediate update og Home-Assistant. Not really a problem for normal sleep-intervals, but i like to have it updated asap if I can.
Home-Assistant Automation
In automations.yaml I have set up this automation to trigger my Wake-Up Light script.
The trigger is 900 sec (or 15 min) before the time set in input_datetime.flemming_phone_next_alarm_date_and_time. This is compared to the current time set by sensor.date_time.
I also have a condition that input_boolean.flemming_phone_alarm_set needs to be on to trigger, this prevents the automation to run if the alarm is not activated.
I have also set a condition that input_boolean.flemming_home (my presence sensor) needs to be on. It’s no point to trigger it if i am sleeping somewhere else.
- id: '1570917544192'
alias: Morgen Rutine
trigger:
- platform: template
value_template: >
{% set alarm_time = as_timestamp(states('input_datetime.flemming_phone_next_alarm_date_and_time')) %}
{% set time_now = as_timestamp(states('sensor.date_time').replace(',','')) %}
{{ time_now >= ( alarm_time - 900 ) }}
condition:
- condition: state
entity_id: input_boolean.flemming_phone_alarm_set
state: 'on'
- condition: state
entity_id: input_boolean.flemming_home
state: 'on'
action:
- alias: ''
data: {}
service: script.wakeup_light_soverom
And below is my wake-up script in scripts.yaml.
It is dimming up slowly from lowest to highest brightnes with diferent colors and ending in a cold white color.
I am using Deconz and Gledopto GL-B-008Z zigbee bulbs. they support both color, cold white and warm white.
The problem with using color-mode in this setup is that even the highest brightnes is just equal to around 10% of the brightnes in white-mode.
I have yet not found a way to make a smooth transision between white in color-mode and white in white-mode, but I will investigate the possibilities of doing this in the future.
wakeup_light_soverom:
alias: Wake-up Light Soverom
sequence:
- data:
brightness: 1
entity_id: light.zigbee_soverom
xy_color:
- 0.67
- 0.39
service: light.turn_on
- delay:
seconds: 1
- data:
brightness: 85
entity_id: light.zigbee_soverom
transition: 12
xy_color:
- 0.65
- 0.41
service: light.turn_on
- delay:
seconds: 15
- data:
brightness: 170
entity_id: light.zigbee_soverom
transition: 12
xy_color:
- 0.6
- 0.4
service: light.turn_on
- delay:
seconds: 15
- data:
brightness: 255
entity_id: light.zigbee_soverom
transition: 12
xy_color:
- 0.48
- 0.4
service: light.turn_on
- delay:
seconds: 15
- data:
entity_id: light.zigbee_soverom
transition: 12
color_name: white
service: light.turn_on
- delay:
seconds: 15
I recorded a video for the above script (It has some auto-focus problems, and looks like it removed a little of the white in the end).
If you have a better Wake-Up-Light script, feel free to share in the comments below.
Software versions used in this setup:
- Home-Assistant v0.100.3
- Tasker .5.6
- AutoAlarm v1.1.1
- Android v9, G965FXXU7CSI6 (Samsung Galaxy S9+)
Sources
- https://community.home-assistant.io/t/node-red-set-datetime-from-payload
- https://www.reddit.com/r/tasker/comments/68ffqx/how_can_i_check_if_variable_is_string_or_number/
- https://www.home-assistant.io/integrations/time_date
- https://community.home-assistant.io/t/trigger-automation-15-minutes-before-date-time-stored-in-input-datetime/
- https://community.home-assistant.io/t/wake-up-sunrise-simulation-with-the-philips-hue-and-sleep-as-android
https://housemethod.com/wellness/science-behind-sunrise-clocks/