Firstly, Iâd like to apologise to jwoodard for hi-jacking his thread.
Phil,
Yeah it threw me too. I have an automation that when it starts, triggered by the light coming on, checks that timer enable is set for that light and if it is, it cancels the old timer (script) and then re-initialises it
- alias: au_light_wc_offdelay
trigger:
- platform: state
entity_id: light.fib_fgd212dim2_wc_level
from: 'off' ################# <--- This the bit in question here
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_light_wc_timer_enable
state: 'on'
action:
- service: script.turn_off
entity_id: script.sc_light_wc_timer
- service: script.sc_light_wc_timer
So the script takes a number from an input_number and waits that length of time before turning the light off. (Interesting point here is that after the light turns on the script shows running, turn the script off (unused items scripts toggle the said script) it appears to turn off then comes back on after 4 secs or so, wait the full period and it then turns the script off itself - but it was not running as the light does not turn off it just stays on. But the above automation is just to set the âdelay offâ .
Regardless, the above script (without the " from: âoffâ ") worked fine ⌠(this was stage 1)
So the lights are set in different groups and the required light levels change through the day.
The light in a specific group comes on and another automation checks what the level should be and applies it : -
- alias: au_aalight_lghtonbth
trigger:
- platform: state
entity_id: light.fib_fgd212dim2_bath_level, light.fib_fgd212dim2_ensu_level, light.fib_fgd212dim2_wc_level
from: 'off'
to: 'on'
action:
- service: light.turn_on
data_template:
entity_id: "{{ trigger.entity_id }}"
brightness_pct: "{{ states('input_number.in_aalight_bth_lvl') | int }}"
(This was stage 2) This sets the level to that stored in : - in_aalight_bth_lvl
It triggers an on but thatâs the on that drives the timer AOK
Everything works tickety-boo
Now lets break things (with stage 3).
So I have a light on and the time of day changes, so I need to change the brightness
That is done and the number stored in (for this case) input_number.in_aalight_bth_lvl
A change in that triggers another automation : -
- alias: au_light_adjust_brightness_wc
trigger:
- platform: state
entity_id: input_number.in_aalight_bth_lvl
condition:
- condition: state
entity_id: light.fib_fgd212dim2_wc_level
state: 'on'
action:
- service: light.turn_on
entity_id: light.fib_fgd212dim2_wc_level
data_template:
brightness_pct: >
{{ states('input_number.in_aalight_bth_lvl') | int }}
So the number changes, triggers the script which then checks that the light is on (remember if I have to switch it on the level is taken care of). So trigger given, condition met, so action follows and to set brightness I have to turn on a light (that is already on) but pass it a new brightness. This some how breaks the timer and Iâm left with a light that stays on forever (well, until the electricity company cuts my power for non-payment of bills).
I added the : -
from: âoffâ
And my timers work once again
Itâs weird but this implies the trigger is not the turning âonâ of a state but simply trying to set it to âonâ regardless that it was already on
Sorry for the long story
I really wanted your (or petroâs) help on the other item : Setting Time Slot States on Re-Start (works but ...) which is about templating not working in a script.
Cheers
Mutt