From 4485529f38fb67568bb19f1792016bceffdb4e83 Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 23 Jan 2026 11:18:22 +0100 Subject: add support for night light mode controlled by HA --- esphome/config/toiletlight.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/esphome/config/toiletlight.yaml b/esphome/config/toiletlight.yaml index 68b4f94..1b1de4c 100644 --- a/esphome/config/toiletlight.yaml +++ b/esphome/config/toiletlight.yaml @@ -130,3 +130,39 @@ output: # accuracy_decimals: 2 # attenuation: auto # update_interval: 1s + +globals: + - id: saved_brightness + type: float + restore_value: yes + initial_value: '1.0' + - id: saved_color_temp + type: float + restore_value: yes + 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: + then: + - if: + condition: + lambda: 'return x.has_value() && x.value();' + then: + - globals.set: + id: saved_brightness + value: !lambda 'return id(toilet).current_values.get_brightness();' + - globals.set: + id: saved_color_temp + value: !lambda 'return id(toilet).current_values.get_color_temperature();' + - light.turn_on: + id: toilet + brightness: 1% + color_temperature: 3000 K + else: + - light.turn_on: + id: toilet + brightness: !lambda 'return id(saved_brightness);' + color_temperature: !lambda 'return id(saved_color_temp);' -- cgit v1.2.3