I have a light that is set up with a input slider timer so that it stays on when there is motion. But if you are still to long the light will turn off on you so if you adjust the delay with the slider this solves the problem. I would like to reset the input side to its default state once the script has run. So if you forget to put the slider back it will do for you. Here is what I have
- alias: "Turn on kitchen lights when there is movement"
trigger:
- platform: state
entity_id: sensor.vision_zp3111_multisensor_4in1_alarm_level_3_1
state: '255'
action:
service: homeassistant.turn_on
entity_id: script.kitchen_timed_light
script.yaml
kitchen_timed_light:
alias: "Turn on kitchen light and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.kitchen_timer_off
- service: homeassistant.turn_on
data:
entity_id: switch.ge_12722_onoff_relay_switch_switch_2_0
# Set new timer
- service: script.turn_on
data:
entity_id: script.kitchen_timer_off
kitchen_timer_off:
alias: "Turn off kitchen light after 1 minutes"
sequence:
- delay: '00:{{ states.input_slider.kitchen_timer.state | int }}:00'
- service_template: >
{%- if not is_state("sensor.vision_zp3111_multisensor_4in1_alarm_level_3_1", "0") -%}
script.turn_on
{% else %}
homeassistant.turn_off
{% endif %}
data_template:
entity_id: >
{%- if not is_state("sensor.vision_zp3111_multisensor_4in1_alarm_level_3_1", "0") -%}
script.kitchen_timer_off_restart
{% else %}
switch.ge_12722_onoff_relay_switch_switch_2_0
{% endif %}
kitchen_timer_off_restart:
alias: "Turn off kitchen light after 1 minutes (restart)"
sequence:
# Cancel current script
- service: script.turn_off
data:
entity_id: script.kitchen_timer_off
# Set new timer
- service: script.turn_on
data:
entity_id: script.kitchen_timer_off
Can’t you simply reset the value at the end of kitchen_timer_off?
I’m not 100% sure that you’re doing this the easiest way. I don’t think you need all of the service template stuff. Just keep retriggering kitchen_timed_light - You’ve already got logic there to cancel the countdown and restart it.
I think your right I have been looking for an example because I don’t know how to reset the input value. I am new and everything is a struggle. Thanks for the help