Phillips Hue Wakeup Light with fade-in

I think you pasted the old version…

Thanks! Fixed it!

I get an error:
ERROR (MainThread) [homeassistant.loader] Unable to find component input_slider

Any idea how to fix it?

Looks like it is input_number now. I have everything working except the icons for Alarm time, Fade-in start time and Fade-in duration are all different. It looks like this:

WakeupLight

1 Like

As a home-assistant newbee - how can I integrate this into my home-assistant setup? I have already connected my hue bridge and can control my light’s but I’m struggling to get the yaml files right. Which is the latest / best version of this and how does one integrate it?

Thanks for your help!

My current working setup is shown below. I can’t figure out how to edit the original post above…

Note that I use the old style of adding automations (“automation old:” instead of dedicated automations.yaml file).

input_number:
  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_number.wakeup_hour.state|length == 3 %}0{% endif %}{{ states.input_number.wakeup_hour.state | int }}:{% if states.input_number.wakeup_minutes.state|length == 3 %}0{% endif %}{{ states.input_number.wakeup_minutes.state | int }}'

  - platform: template
    sensors:
      wakeup_start_time_lights:
        friendly_name: 'Fade-in start time'
        value_template: >
          {% if states.sensor.wakeup_alarm_time and states.input_number.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_number.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_number.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_number.wakeup_hour
      - input_number.wakeup_minutes
      - input_number.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.soverom
          brightness: 1
          kelvin: 1000
      - delay:
          seconds: 1
      - service: light.turn_on
        data_template:
          entity_id: light.soverom
          brightness: 64
          kelvin: 2000
          transition: '{{ (( states.input_number.wakeup_duration.state | float * 60 / 4 )| round ) | int }}'
      - delay: '00:00:{{ (( states.input_number.wakeup_duration.state | float * 60 / 4 )| round ) | int }}'
      - service: light.turn_on
        data_template:
          entity_id: light.soverom
          brightness: 128
          kelvin: 3000
          transition: '{{ (( states.input_number.wakeup_duration.state | float * 60 / 4 )| round ) | int }}'
      - delay: '00:00:{{ (( states.input_number.wakeup_duration.state | float * 60 / 4 )| round ) | int }}'
      - service: light.turn_on
        data_template:
          entity_id: light.soverom
          brightness: 191
          kelvin: 4000
          transition: '{{ (( states.input_number.wakeup_duration.state | float * 60 / 4 )| round ) | int }}'
      - delay: '00:00:{{ (( states.input_number.wakeup_duration.state | float * 60 / 4 )| round ) | int }}'
      - service: light.turn_on
        data_template:
          entity_id: light.soverom
          brightness: 255
          kelvin: 5000
          transition: '{{ (( states.input_number.wakeup_duration.state | float * 60 / 4 )| round ) | int }}'
4 Likes

So i got it on my screen but i get these errors:

2018-01-11 23:29:58 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [wakeup_bedroom] is an invalid option for [script]. Check: script->script->test_push->wakeup_bedroom. (See /home/homeassistant/.homeassistant/configuration.yaml, line 45). Please check the docs at https://home-assistant.io/components/script/
2018-01-11 23:29:58 ERROR (MainThread) [homeassistant.setup] Setup failed for script: Invalid config.
2018-01-11 23:30:13 WARNING (MainThread) [homeassistant.setup] Setup of light is taking over 10 seconds.
2018-01-11 23:30:51 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Fade-in start time: UndefinedError: list object has no element 1

ANy idea what it could be?

Thanks for this, it works amazing!
For those that have issues with triggering the automation you may need to enable the time sensor:

I’m using hue color lamps and made a sequence that goes from very dim red to dim yellow to brighter white
I found that sometimes the transition would not happen and think it is due to delay being the same, so I just do transition minus 1 second:

bedroom_rear_wakeup_light:
  alias: 'Wakeup lighting, smooth transition'
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 0
        rgb_color: [128,0,0]
    - delay:
        seconds: 0
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 1
        rgb_color: [128,0,0]
    - delay:
        seconds: 1
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 16
        rgb_color: [128,0,0]
        transition: '{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 -1 ) | round ) | int }}'
    - delay: '00:00:{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 ) | round ) | int }}'
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 32
        rgb_color: [192,64,0]
        transition: '{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 - 1 ) | round ) | int }}'
    - delay: '00:00:{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 ) | round ) | int }}'
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 48
        rgb_color: [224,128,32]
        transition: '{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 - 1 ) | round ) | int }}'
    - delay: '00:00:{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 ) | round ) | int }}'
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 96
        rgb_color: [255,176,96]
        transition: '{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 - 1 ) | round ) | int }}'
    - delay: '00:00:{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 ) | round ) | int }}'
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 112
        rgb_color: [255,224,160]
        transition: '{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 - 1 ) | round ) | int }}'
    - delay: '00:00:{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 ) | round ) | int }}'
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 128
        rgb_color: [255,255,224]
        transition: '{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 - 1 ) | round ) | int }}'
    - delay: '00:00:{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 ) | round ) | int }}'
    - service: light.turn_on
      data_template:
        entity_id: group.bedroom_rear_bed_lights
        brightness: 144
        rgb_color: [240,255,255]
        transition: '{{ (( states.input_number.bedroom_rear_wakeup_duration.state | float * 60 / 7 - 1 ) | round ) | int }}'

edit: improved colors for a smoother transition (i hate too much greens), also the first step in the sequence which sets the color with a 0 brightness may (or may not) reduce the initial flash that happens when the lights were previously turned off with a high brightness setting, may need to find a better workaround for that

4 Likes

I’ve also tried setting the colour before turning the lamp on, but I do not think this work when the brightness is 0. The lamp needs to turn on (brightness > 0) to change color.

It should not be necessary to decrease the transition with 1 second. When a new command is sent to hue the current transition will be terminated anyway…

Yes I noticed the light still flashes with that first step. I didn’t know the transition is canceled so guess I can drop the -1 :slight_smile:

Thank’s so much, combining the variable fade-in time with a colored sunrise is exactly what I was looking for. Sometimes the light flashes at the start but this seems to be varying (I can’t make it always flash).

1 Like

Hum…

Can’t seem to get this to work, or even figure out where it is crashing.

I have *.automations on Debug level, and this is all I’m getting:

018-05-25 16:38:01 INFO (MainThread) [homeassistant.components.automation] Executing WakeUp Light Bedroom

So it is running, but not actually doing anything. I did add the date sensor, but that didnt help. I also (obviously) changed the name of my light group for Hue.

Any thoughts on how to debug / trace the issue?

**EDIT:
Ha! found the issue in the last place I look… the info “button”. I renamed the script section while testing and that was the issue. Works great! Thanks!

I have the same issue… any ideas?

Nope… Not working

Might be a silly question but why don’t you try the built in routines in the Hue App? Seems to be possible natively to smooth in at wake up ? And very reliable too…

1 Like

It’s too simple and not integrated :slight_smile:

I want to trigger other stuf at the same time after my alarm goes off (connected to HA).
My alarm goes off a different time everyday.

@dvbit @VGE

sure, you’re both right, Hue automation is quite simple, and coming from Hassio or Ha quite a leap back in possibilities. Still people are creating the labs, which we can use native, and I believe also through the api, hence via Ha. Switching my motion sensors like that too, works super.

Hue has it advantages in stability and most of all reliability compared to Ha though. Thats why I always try to use the Hue native services/lights/sensors etc and call these in the Ha setup if needed.

I havent tested the labs. Any good ones? Will read on it this weekend. Maby its a solution to my problem.

mostly christmas lights, fake thunders and other flashes.
in the regular routines you might find wake up strategies.

also just so you know theres the circadian lights settings by @mastermarkush adapting the lights to the circadian settings of the day Circadian light with Philips Hue, independent from world clocks ;-) Nice!