Properly fix light-switching-while-holding bug

Use a global to keep the state here, and set it while a hold is active,
only clearing it afterwards. While held calls to `light_off` are skipped
entirely.
This commit is contained in:
2025-10-10 16:49:45 -04:00
parent b9e92cd46e
commit a259542870

View File

@@ -164,39 +164,35 @@ globals:
restore_value: yes restore_value: yes
initial_value: '"mww_computer"' initial_value: '"mww_computer"'
- id: light_is_holding
type: bool
restore_value: no
initial_value: 'false'
script: script:
- id: presence_light_on
then:
if:
condition:
- switch.is_on: enable_presence_led
- light.is_off: output_led
then:
- light.turn_on:
id: output_led
brightness: 25%
red: 1
green: 1
blue: 1
transition_length: 1s
- id: light_off - id: light_off
then: then:
if: - if:
condition: condition:
- binary_sensor.is_on: supersensor_occupancy lambda: 'return id(light_is_holding);'
- switch.is_on: enable_presence_led then:
then: - stop:
- light.turn_on: - if:
id: output_led condition:
brightness: 25% - binary_sensor.is_on: supersensor_occupancy
red: 1 - switch.is_on: enable_presence_led
green: 1 then:
blue: 1 - light.turn_on:
transition_length: 1s id: output_led
else: brightness: 25%
- light.turn_off: red: 1
id: output_led green: 1
transition_length: 1s blue: 1
transition_length: 1s
else:
- light.turn_off:
id: output_led
transition_length: 1s
- id: pir_handler - id: pir_handler
then: then:
@@ -556,7 +552,13 @@ light:
- automation: - automation:
name: hold name: hold
sequence: sequence:
- globals.set:
id: light_is_holding
value: "true"
- delay: 5s - delay: 5s
- globals.set:
id: light_is_holding
value: "false"
- script.execute: light_off - script.execute: light_off
output: output:
@@ -836,7 +838,7 @@ binary_sensor:
device_class: occupancy device_class: occupancy
on_state: on_state:
then: then:
- script.execute: presence_light_on - script.execute: light_off
- platform: gpio - platform: gpio
name: "PIR GPIO" name: "PIR GPIO"