I’ve made a wakeup light that uses the smooth transition on a Phillips Hue group (Room).
You can set the transition duration in minutes so that the maximum brightness is reached on “Alarm time”.
configuration.yaml
input_slider:
wakeup_hour:
name: Hour
icon: mdi:clock-in
initial: 6
min: 0
max: 23
step: 1
wakeup_minutes:
name: Minutes
icon: mdi:clock-in
initial: 30
min: 0
max: 55
step: 5
wakeup_duration:
name: Light fade-in duration
icon: mdi:clock-in
initial: 10
min: 5
max: 60
step: 5
input_boolean:
wakeup:
name: 'Enable wakeup light'
icon: mdi:power
initial: off
wakeup_weekends:
name: 'Wakeup weekends'
icon: mdi:power
initial: off
sensor:
- platform: template
sensors:
wakeup_alarm_time:
friendly_name: 'Alarm time'
value_template: '{% if states.input_slider.wakeup_hour.state|length == 3 %}0{% endif %}{{ states.input_slider.wakeup_hour.state | int }}:{% if states.input_slider.wakeup_minutes.state|length == 3 %}0{% endif %}{{ states.input_slider.wakeup_minutes.state | int }}'
- platform: template
sensors:
wakeup_start_time_lights:
friendly_name: 'Fade-in start time'
value_template: >
{% if states.wakeup_alarm_time and states.input_slider.wakeup_duration %}
{% set alarmtime = states.sensor.wakeup_alarm_time.state %}
{% set alarm_hour = alarmtime.split(":")[0] | int %}
{% set alarm_min = alarmtime.split(":")[1] | int %}
{% set light_dur = states.input_slider.wakeup_duration.state | int %}
{% set alarm_min_light = alarm_min - light_dur %}
{% if alarm_min_light < 0 %}
{% set alarm_min_light = alarm_min_light + 60 %}
{% set alarm_hour_light = alarm_hour - 1 %}
{% if alarm_hour_light < 0 %}{% set alarm_hour_light = 23 %}{% endif %}
{% if alarm_hour_light < 10 %}0{% endif %}{{ alarm_hour_light}}:{% if alarm_min_light < 10 %}0{% endif %}{{ alarm_min_light }}
{% else %}
{% if alarm_hour < 10 %}0{% endif %}{{ alarm_hour }}:{% if alarm_min_light < 10 %}0{% endif %}{{ alarm_min_light }}
{% endif %}
{% endif %}
- platform: template
sensors:
wakeup_fadein_duration:
friendly_name: 'Fade-in duration'
value_template: '{{ states.input_slider.wakeup_duration.state | int }}'
unit_of_measurement: 'min'
group:
wakeuplight:
name: Wakeup light
control: hidden
entities:
- sensor.wakeup_alarm_time
- sensor.wakeup_start_time_lights
- sensor.wakeup_fadein_duration
- input_slider.wakeup_hour
- input_slider.wakeup_minutes
- input_slider.wakeup_duration
- input_boolean.wakeup
- input_boolean.wakeup_weekends
automation old:
- alias: 'WakeUp Light Bedroom'
hide_entity: True
trigger:
platform: template
value_template: '{{ states.sensor.time.state == states.sensor.wakeup_start_time_lights.state }}'
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.wakeup
state: 'on'
- condition: or
conditions:
- condition: state
entity_id: input_boolean.wakeup_weekends
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
service: script.wakeup_bedroom
script:
wakeup_bedroom:
alias: 'Wakeup lighting, smooth transition'
sequence:
- service: light.turn_on
data_template:
entity_id: light.bedroom
brightness: 1
xy_color: [0.3698, 0.3723]
- delay:
seconds: 1
- service: light.turn_on
data_template:
entity_id: light.bedroom
brightness: 255
transition: '{{ states.input_slider.wakeup_duration.state | multiply(60) | int }}'
# EDIT: Everything below is not longer necessary as Hass now supports Hue natively!
script:
wakeup_bedroom:
alias: 'Wakeup lighting, smooth transition'
sequence:
- service: shell_command.wakeup_init
- service: shell_command.wakeup_transition
shell_command:
wakeup_init: "/home/homeassistant/.homeassistant/bash_scripts/phue_control.sh bedroom '{\"on\":true,\"bri\":1,\"xy\":[0.3698,0.3723],\"transitiontime\":50}'"
wakeup_transition: "/home/homeassistant/.homeassistant/bash_scripts/phue_control.sh bedroom '{\"bri\":254,\"transitiontime\":{{ states.input_slider.wakeup_duration.state | multiply(600) | int }}}'"
EDIT-1: I created this “app” a long time ago and I just found out that hass now supports Phillips Hue natively which means that the bash script (phue_control.sh) below is no longer needed!
EDIT-2: Added input booleans
The two shell commands uses a bash script (phue_control.sh) that I wrote to be able to use the groups (Rooms) and simultaneous transition function. I used the instructions given here to create an API key and to find the ID’s for my hue groups and lights. The wakeup_init sets the color and minimum brightness and the wakeup_transition sets the transition time and target brightness (max=254).
phue_control.sh
#!/bin/bash
# INPUT: hue IP & api key
HOST=<YOUR HUE BRIDGE IP>
APIKEY=<YOUR KEY>
# group/light friendly name
FNAME=$1
# hue command
COMMAND=$2
# INPUT: specify hue type ("groups" or "lights") and ID
case $FNAME in
bedroom)
TYPE="groups"
ID=2
;;
nattbord_lorentz)
TYPE="lights"
ID=1
;;
nattbord_karen)
TYPE="lights"
ID=2
;;
sofaspotter)
TYPE="groups"
ID=1
;;
spisebord)
TYPE="lights"
ID=3
;;
*)
esac
if [ "$TYPE" == "groups" ] ; then
AS="action"
else
AS="state"
fi
curl -X PUT -H "Content-Type: application/json" -d $COMMAND http://$HOST/api/$APIKEY/$TYPE/$ID/$AS