I’m trying to sync my room lights brightness to my Philips wake-up light when it wakes me in the morning. I have the wake-up light on a smart switch with a power sensor.
There’s something off in my template (“missed comma between flow collection entries”), but this is more or less what it should be. Anyone proficient in template syntax that can help a little?
- alias: Wake-up light met verlichting zeekamer
trigger:
- platform: numeric_state
entity_id: sensor.wake_up_light
condition:
- condition: time
before: '12:00:00'
after: '03:00:00'
- condition: numeric_state
entity_id: sensor.wake_up_light
above: '0.4'
action:
- service: light.turn_on
data_template:
entity_id: light.spots_zeekamer_43, light.hanglamp_zeekamer_40
brightness:
{% if trigger.to_state.state > 4 %}
255
{% elif trigger.to_state.state > 2 %}
205
{% elif trigger.to_state.state > 1.25 %}
155
{% elif trigger.to_state.state > 0.8 %}
105
{% elif trigger.to_state.state > 0.56 %}
55
{% elif trigger.to_state.state > 0.45 %}
5
{% else %}
0
{% endif %}
petro
(Petro)
February 16, 2019, 11:58am
2
the state property of any state object is always a string. Gotta convert it to what you want it to be.
- alias: Wake-up light met verlichting zeekamer
trigger:
- platform: numeric_state
entity_id: sensor.wake_up_light
condition:
- condition: time
before: '12:00:00'
after: '03:00:00'
- condition: numeric_state
entity_id: sensor.wake_up_light
above: '0.4'
action:
- service: light.turn_on
data_template:
entity_id: light.spots_zeekamer_43, light.hanglamp_zeekamer_40
brightness:
{% set wakeup_state = trigger.to_state.state | float %}
{% if wakeup_state > 4 %}
255
{% elif wakeup_state > 2 %}
205
{% elif wakeup_state > 1.25 %}
155
{% elif wakeup_state > 0.8 %}
105
{% elif wakeup_state > 0.56 %}
55
{% elif wakeup_state > 0.45 %}
5
{% else %}
0
{% endif %}
1 Like
Thanks! Didn’t know that, I’ve inserted the ‘set wakeup_state’ line.
Had to change a few other things to get it working properly:
Solved the “missed comma between flow collection entries” error: turns out single quotes are required at start and end of the brightness template.
I used a lowpass filter sensor to smooth the output of the power sensor, as it fluctuated too heavily at low wattage.
Here’s what I have now:
- alias: Wake-up light met verlichting zeekamer
trigger:
- platform: state
entity_id: sensor.wake_up_light_filtered
condition:
- condition: time
before: '13:00:00'
after: '03:00:00'
- condition: numeric_state
entity_id: sensor.wake_up_light_filtered
above: '0.299'
action:
- service: light.turn_on
data_template:
entity_id: light.spots_zeekamer_43, light.hanglamp_zeekamer_40
brightness:
'{% set wakeup_state = trigger.to_state.state | float %}
{% if wakeup_state > 3 %}
255
{% elif wakeup_state > 2 %}
175
{% elif wakeup_state > 1.2 %}
125
{% elif wakeup_state > 0.79 %}
85
{% elif wakeup_state > 0.56 %}
55
{% elif wakeup_state > 0.36 %}
30
{% elif wakeup_state > 0.33 %}
15
{% elif wakeup_state > 0.31 %}
8
{% else %}
3
{% endif %}'
I used the condition value ‘0.299’ as I’m never sure above/below includes the value itself, and am too lazy to test
For anybody who wants to try this: I used a Philips Wake-up Light HF3505 connected to a Broadlink SP3S smart switch w/ power sensor. Used a Xiaomi smart switch before but its power readouts have substantial delays, making it unusable for this automation.