From 0bc9a4c0ee71743089ba75840e5d8b37d7417dc8 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 9 Apr 2026 21:24:45 +0200 Subject: toilet: switch to always-on setup + presence on gpio --- esphome/config/toiletlight.yaml | 64 +++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/esphome/config/toiletlight.yaml b/esphome/config/toiletlight.yaml index 35b968e..cd39e6b 100644 --- a/esphome/config/toiletlight.yaml +++ b/esphome/config/toiletlight.yaml @@ -77,7 +77,7 @@ output: pin: GPIO1 frequency: 3900 Hz channel: 0 - min_power: 0.04 + min_power: 0.02 zero_means_zero: true - id: pwm_warm @@ -146,31 +146,39 @@ globals: initial_value: '222.0' # 4500K binary_sensor: - - platform: homeassistant - name: "Nightlight enabled from Home Assistant" - entity_id: input_boolean.toilet_light_nightlight - on_state_change: + - platform: gpio + name: "Presence detector" + id: presence_detector + pin: + number: GPIO10 + mode: INPUT_PULLUP + inverted: true + filters: + - delayed_on: 10ms + - delayed_off: 10ms + on_state: then: - - if: - condition: - lambda: 'return x.has_value() && x.value();' - then: - - lambda: |- - if (!id(saved_values)) { - id(saved_brightness) = id(toilet).current_values.get_brightness(); - id(saved_color_temp) = id(toilet).current_values.get_color_temperature(); - id(saved_values) = true; - } - - light.turn_on: - id: toilet - brightness: 1% - color_temperature: 3000 K - else: - - lambda: |- - if (id(saved_values)) { - auto call = id(toilet).turn_on(); - call.set_brightness(id(saved_brightness)); - call.set_color_temperature(id(saved_color_temp)); - call.perform(); - id(saved_values) = false; - } + - lambda: 'id(toilet).make_call().set_state(x).perform();' + trigger_on_initial_state: true + +switch: + - platform: template + name: "Nightlight" + icon: "mdi:lightbulb-night" + lambda: 'return id(saved_values);' + turn_on_action: + - lambda: |- + id(saved_brightness) = id(toilet).current_values.get_brightness(); + id(saved_color_temp) = id(toilet).current_values.get_color_temperature(); + id(saved_values) = true; + - light.control: + id: toilet + brightness: 1% + color_temperature: 3000 K + turn_off_action: + - lambda: |- + auto call = id(toilet).make_call(); + call.set_brightness(id(saved_brightness)); + call.set_color_temperature(id(saved_color_temp)); + call.perform(); + id(saved_values) = false; -- cgit v1.2.3