From a25954287006aebcbfcdd7a73e6a65b29037e443 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 10 Oct 2025 16:49:45 -0400 Subject: [PATCH] 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. --- supersensor.yaml | 64 +++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/supersensor.yaml b/supersensor.yaml index 8e0f40c..931c731 100644 --- a/supersensor.yaml +++ b/supersensor.yaml @@ -164,39 +164,35 @@ globals: restore_value: yes initial_value: '"mww_computer"' + - id: light_is_holding + type: bool + restore_value: no + initial_value: 'false' + 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 then: - if: - condition: - - binary_sensor.is_on: supersensor_occupancy - - switch.is_on: enable_presence_led - then: - - light.turn_on: - id: output_led - brightness: 25% - red: 1 - green: 1 - blue: 1 - transition_length: 1s - else: - - light.turn_off: - id: output_led - transition_length: 1s + - if: + condition: + lambda: 'return id(light_is_holding);' + then: + - stop: + - if: + condition: + - binary_sensor.is_on: supersensor_occupancy + - switch.is_on: enable_presence_led + then: + - light.turn_on: + id: output_led + brightness: 25% + red: 1 + green: 1 + blue: 1 + transition_length: 1s + else: + - light.turn_off: + id: output_led + transition_length: 1s - id: pir_handler then: @@ -556,7 +552,13 @@ light: - automation: name: hold sequence: + - globals.set: + id: light_is_holding + value: "true" - delay: 5s + - globals.set: + id: light_is_holding + value: "false" - script.execute: light_off output: @@ -836,7 +838,7 @@ binary_sensor: device_class: occupancy on_state: then: - - script.execute: presence_light_on + - script.execute: light_off - platform: gpio name: "PIR GPIO"