From bedc5fd17906bce39b039d8e306b762e4d59d6ff Mon Sep 17 00:00:00 2001 From: ttrabatt Date: Thu, 29 May 2025 22:58:23 +0200 Subject: [PATCH] Garage presence light VIP --- automations.yaml | 12 ++ .../homeassistant/presence_light.yaml | 155 ++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 blueprints/automation/homeassistant/presence_light.yaml diff --git a/automations.yaml b/automations.yaml index da8a566..9bbd6ae 100644 --- a/automations.yaml +++ b/automations.yaml @@ -112,3 +112,15 @@ description: '' use_blueprint: path: homeassistant/test_macro.yaml +- id: '1748185066312' + alias: Luce-Garage + description: '' + use_blueprint: + path: homeassistant/presence_light.yaml + input: + presence_entity1: binary_sensor.presenza_garage_occupancy + light_target: + device_id: d5b217920e2f4fe83e0496257b27e39c + use_sun: false + dont_disturb: false + no_presence_wait: 120 diff --git a/blueprints/automation/homeassistant/presence_light.yaml b/blueprints/automation/homeassistant/presence_light.yaml new file mode 100644 index 0000000..1e138d0 --- /dev/null +++ b/blueprints/automation/homeassistant/presence_light.yaml @@ -0,0 +1,155 @@ +blueprint: + name: Presence-activated-Light + description: Turn on a light when presence is detected + domain: automation + author: Tiziano Trabattoni + input: + presence_entity1: + name: presence-sensor1 + description: First Sensor presence entity + selector: + entity: + filter: + device_class: occupancy + domain: binary_sensor + light_target: + name: Light + description: Entity of the Lamp to be controlled + selector: + target: + entity: + domain: light + use_sun: + name: Sun_driven + description: Controlled by sunrise and sunset flag + default: on + selector: + boolean: + dont_disturb: + name: dont_disturb_light_control + description: Controls if lamp brightness has to be reduced to not disturb + default: on + selector: + boolean: + no_presence_wait: + name: Wait time + description: Time to leave the light on after last presence is detected. + default: 20 + selector: + number: + min: 0 + max: 300 + unit_of_measurement: seconds + +# Every motion state change is captured and managed by the script therefore we need to restart by queueing triggers +# in this automation the poweroff of light is started only if all managed motion sensor are in clear state (= "off") +mode: queued +max_exceeded: silent + +triggers: + - trigger: state + entity_id: !input presence_entity1 + from: "off" + to: "on" + id: presence_entity1_on + + - trigger: state + entity_id: !input presence_entity1 + from: "on" + to: "off" + id: presence_entity1_off + +variables: + use_sun_flag: !input use_sun + dont_disturb_flag: !input dont_disturb + light_target_var: !input light_target + presence_entity1_var: !input presence_entity1 + +actions: + - choose: + # Conditions for triggering on light + - conditions: + - condition: trigger + id: + - presence_entity1_on + # - presence_entity2_on + # - presence_entity3_on + sequence: + - if: + - condition: template + value_template: "{{ use_sun_flag }}" + then: # Sun and luminescence controlled + - if: + - or: + # external light is LOW (below Helper daylight_luminescence set value) + - condition: template + value_template: "{{ ( states('sensor.esterno_luminosita_illuminance_lux') | int ) < ( states('input_number.daylight_luminescence') | int ) }}" + # after sunrise and before sunset + - condition: sun + after: sunset + after_offset: "-01:00:00" + before: sunrise + before_offset: "+01:00:00" + then: + - if: + - and: + - condition: template + value_template: "{{ dont_disturb_flag }}" + - condition: template + value_template: "{{ is_state('binary_sensor.dont_disturb_nighttime', 'on') }}" + then: + - action: light.turn_on + target: !input light_target + data: + brightness_pct: "{{ states('input_number.dont_disturb_light_brightness') | float }}" + color_temp_kelvin: 2500 + else: + - action: light.turn_on + target: !input light_target + data: + brightness_pct: 100 + color_temp_kelvin: 2500 + else: # Always active + - if: + - and: + - condition: template + value_template: "{{ dont_disturb_flag }}" + - condition: template + value_template: "{{ is_state('binary_sensor.dont_disturb_nighttime', 'on') }}" + then: + - action: light.turn_on + target: !input light_target + data: + brightness_pct: "{{ states('input_number.dont_disturb_light_brightness') | float }}" + color_temp_kelvin: 2500 + else: + - action: light.turn_on + target: !input light_target + data: + brightness_pct: 100 + color_temp_kelvin: 2500 + + # conditions for triggering off lights + - conditions: + - condition: trigger + id: + - presence_entity1_off + # - presence_entity2_off + # - presence_entity3_off + sequence: + - if: + - alias: "None of motion sensor are detected" + condition: not + conditions: + - condition: template + value_template: "{{ is_state(presence_entity1_var, 'on') }}" + # - condition: template + # value_template: "{{ is_state(presence_entity2_var, 'on') }}" + # - condition: template + # value_template: "{{ is_state(presence_entity3_var, 'on') }}" + then: + - alias: "Wait for delay set before turn off" + delay: !input no_presence_wait + - alias: "Turn off the light" + action: light.turn_off + target: !input light_target