From 28a73cb136b18b0407e0e15de4fafa881cc40114 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 12 Oct 2023 13:05:16 +0200 Subject: bedlight: add child lock --- esphome/config/bedlight.yaml | 73 ++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/esphome/config/bedlight.yaml b/esphome/config/bedlight.yaml index f34f021..7688e79 100644 --- a/esphome/config/bedlight.yaml +++ b/esphome/config/bedlight.yaml @@ -5,13 +5,17 @@ esphome: #esp8266_restore_from_flash: true # light default values - #on_boot: - # then: - # - light.control: - # id: bed - # state: on - # brightness: 10% - # color_temperature: 330.0 mireds + on_boot: + then: + - lock.template.publish: + id: child_lock + state: UNLOCKED + # light default values + #- light.control: + # id: bed + # state: on + # brightness: 10% + # color_temperature: 330.0 mireds # Enable logging logger: @@ -122,6 +126,13 @@ script: then: - delay: 10s - lambda: 'id(g_dim_level) = abs(id(g_dim_level));' + - id: reset_child_lock + mode: restart + then: + - delay: 30min + - lock.template.publish: + id: child_lock + state: UNLOCKED binary_sensor: - id: user_button @@ -133,25 +144,33 @@ binary_sensor: min_length: 30ms max_length: 350ms then: - - logger.log: "on_click" - # TODO: if brightness is low, turn on + transition is also slow - - light.toggle: bed - # dim up per default unless brightness is 95% - - lambda: |- - id(g_dim_level) = abs(id(g_dim_level)); - if (id(bed).current_values.get_brightness() >= 0.95) - id(g_dim_level) *= -1; + - if: + condition: + lock.is_unlocked: child_lock + then: + - logger.log: "on_click" + # TODO: if brightness is low, turn on + transition is also slow + - light.toggle: bed + # dim up per default unless brightness is 95% + - lambda: |- + id(g_dim_level) = abs(id(g_dim_level)); + if (id(bed).current_values.get_brightness() >= 0.95) + id(g_dim_level) *= -1; on_press: then: - delay: 500ms - if: condition: - # make sure button is still pressed - binary_sensor.is_on: user_button + and: + - lock.is_unlocked: child_lock + # make sure button is still pressed + - binary_sensor.is_on: user_button then: - while: condition: - binary_sensor.is_on: user_button + and: + - lock.is_unlocked: child_lock + - binary_sensor.is_on: user_button then: - logger.log: "on_press" - light.dim_relative: @@ -172,5 +191,19 @@ binary_sensor: - script.execute: reset_dim_direction on_double_click: then: - - homeassistant.event: - event: esphome.double_click + - if: + condition: + lock.is_unlocked: child_lock + then: + - homeassistant.event: + event: esphome.double_click + +lock: + - id: child_lock + platform: template + name: "Child Lock" + optimistic: true + on_lock: + - script.execute: reset_child_lock + on_unlock: + - script.stop: reset_child_lock -- cgit v1.2.3