right, please do. Thing is, Ive just tested the same setup, with a few adjusted entities in my HA instance, and the original script/automation set works as expected, and no errors arise…
Did have to make 1 extra service call, which I had expected tbh. We have to cancel the script first, before we call it again in the automation. This is to prevent calling an already running script, in the case of turn_on.
What I did notice when copying from the community here, is sometimes incorrect quotes are used. These quotes pass the config checker, but don’t pass the real life situation. And have unrelated errors in the logs, causing one to search in the wrong direction…
So always check all quotes extra before hating restart.
this is what I just tested:
script:
switch_off_lights_delay:
alias: Switch off lights with delay
sequence:
- delay:
minutes: >
{{ '1' if states('input_number.presence_timer' ) | int >= 150 else '2' }}
- service: light.turn_off
entity_id: light.living
and automation:
- alias: 'Living lights off when no motion'
id: 'Living lights off when no motion'
initial_state: 'on'
trigger:
platform: state
entity_id: binary_sensor.auditorium_motion_sensor
condition: []
action:
- service: script.turn_off
entity_id: script.switch_off_lights_delay
- service_template: >
script.turn_{{ 'on' if is_state('binary_sensor.auditorium_motion_sensor','off') else 'off' }}
entity_id: script.switch_off_lights_delay
tested the various timings with the input_numner and the correct change in switch_off delay.
also tested movement during the delay, causing restart of the automation, script and timing again.
so for now, this minimal setup has your desired effect.
there’s one thing you need to consider still:
what will happen when the humidity changes to below/above the threshold during the delay.
Right now, humidity isn’t a trigger for the automation, and I think that is correct. One could argue an extra numeric trigger for humidity with a below, or above setting, depending on the rest of the automation.
This would however complicate things considerably, so Id suggest you see first how you fare with the current combination, and come back with results, and see if a further adjustment would be desired.
Also, set the Hue app accessory details to a correct level of movement and light sensitivity. We can program everything you want in HA, but if the App sets the motion sensor to insensitive, it won’t ever trigger …