I’m hoping that someone can look over my code and see what I’m doing wrong.
Some background I started with HA Nov 4th 2017 (so 5 weeks ago) and this is where I have gotten.
I am just testing stuff out and building my UI, I only have a Z-wave light dimmer at the moment but if I can get that exactly as I want the rest should be a doddle ; - ) I’ve sorted Weather, Tabs, Cards, Default View, Zones and Customisation. So I’m progressing a pace thanks mainly to reading other peoples issues and solutions.
But … my biggest bugbear was people leaving the cloakroom light on.
I used the dimmer in a test rig and was very impressed with out of box functionality, low voltage switch loop for light switch toggling on change of state (good for 2 or even 3 or 4 way switches), paired with Z-stick, set notification to basic and can both act on switch and see result, from HA.
So created an automation to turn light off after 10 mins :-
In automations.yaml
- alias: Light_F0_CR_Tmr_OFF # when light comes on timer starts to turn it off again
trigger:
platform: state
entity_id: light.aeotec_dsc19103_micro_smart_dimmer_2nd_edition_level
to: 'on'
for:
#minutes: 10
seconds: 600
action:
service: light.turn_off
entity_id: light.aeotec_dsc19103_micro_smart_dimmer_2nd_edition_level
Works great ; - )
Now I wanted to be able to change the light level, okay use a slider and have the change of slider control the brightness.
So slider is 0 to 255 and I set initial value to 152 (60%), again, works great !
In input_number.yaml
light_f0_cr_ctrl:
name: CRL Brightness
initial: 152
min: 0
max: 255
step: 1
And in automations.yaml I have another automation, so that it comes on at the right level-
- alias: Light_F0_CR_To_On # light comes on at set brightness
trigger:
platform: state
entity_id: light.aeotec_dsc19103_micro_smart_dimmer_2nd_edition_level
to: 'on'
action:
service: light.turn_on
entity_id: light.aeotec_dsc19103_micro_smart_dimmer_2nd_edition_level
data_template:
brightness: '{{ input_number.light_f0_cr_ctrl.state | int }}'
Okay so my next issue is bathroom light at night. I have to stumble in the dark as it will blind me and wake the wife.
So how about at midnight, I set the brightness slider to a lower level, then back up at dawn ? So extra automations for my levels (remember it’s a test rig)
- alias: Light_F0_CR_ToD_LvlAdj1 # adjust light level
trigger:
platform: time
at: '00:30:00'
action:
service: input_number.light_f0_cr_ctrl
data:
value: 64
- alias: Light_F0_CR_ToD_LvlAdj2 # adjust light level
trigger:
platform: sun
event: sunrise
offset: '00:30:00'
action:
service: input_number.light_f0_cr_ctrl
data:
value: 192
- alias: Light_F0_CR_ToD_LvlAdj3 # adjust light level
trigger:
platform: sun
event: sunset
offset: '00:30:00'
action:
service: input_number.light_f0_cr_ctrl
data:
value: 128
Now, what I think I need is an automation where it changes the level (slider) value, and if the light is on, it writes that to the light
- alias: Light F0 Cloak Room Brightness # if level changed light comes on to that level, do I need this ?
trigger:
platform: state
entity_id: input_number.light_f0_cr_ctrl
condition:
- condition: state
entity_id: light.aeotec_dsc19103_micro_smart_dimmer_2nd_edition_level
state: 'on'
action:
service: light.turn_on
**# Note the use of 'data_template:' below for an evaluated variable, rather than the normal 'data:' when using a given value**
entity_id: light.aeotec_dsc19103_micro_smart_dimmer_2nd_edition_level
data_template:
brightness: '{{ trigger.to_state.state | int }}'
This is where it all went wrong and the light does not come on at the slider value, just the initial value, and the slider does not change at all.
And though the ‘{{ input_number.light_f0_cr_ctrl.state | int }}’ worked in the code to spot changes in the slider and update lamp output it does not work in the template checker, so is that a limited sandbox ??? why ?
I hope this is just a simple mistake, please yell if you spot it
Cheers - and thanks just for reading !
Mutt