From cb481ad0ec00d905df59bc75a498ea5acdc1f32a Mon Sep 17 00:00:00 2001 From: ttrabatt Date: Fri, 31 Jan 2025 18:53:01 +0100 Subject: [PATCH] motion light dual NEW test before variable substitution --- automations.yaml | 1 - .../homeassistant/motion-light-new.yaml | 84 ++++++++++++++----- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/automations.yaml b/automations.yaml index 30e112b..1b74a89 100644 --- a/automations.yaml +++ b/automations.yaml @@ -207,7 +207,6 @@ alias: test-pulsante1 description: "" triggers: - - trigger: mqtt topic: "zigbee2mqtt/Pulsante-01" payload: "single" diff --git a/blueprints/automation/homeassistant/motion-light-new.yaml b/blueprints/automation/homeassistant/motion-light-new.yaml index 7921faa..0aee6af 100644 --- a/blueprints/automation/homeassistant/motion-light-new.yaml +++ b/blueprints/automation/homeassistant/motion-light-new.yaml @@ -3,14 +3,14 @@ blueprint: description: Turn on a light when motion is detected NEW. domain: automation source_url: https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml - author: Home Assistant + author: Tiziano Trabattoni input: motion_entity1: name: Motion-sensor1 selector: entity: filter: - device_class: switch + device_class: motion domain: binary_sensor motion_entity2: name: Motion-sensor2 @@ -35,6 +35,13 @@ blueprint: max: 300 unit_of_measurement: seconds +trigger_variables: + _light_target: !input light_target +# motion_entity1_var: +# entity_id: !input motion_entity1 +# motion_entity2_var: +# entity_id: !input motion_entity2 +# # If motion is detected within the delay, # we restart the script. mode: restart @@ -45,27 +52,64 @@ triggers: entity_id: !input motion_entity1 from: "off" to: "on" + id: motion_entity1_on - trigger: state entity_id: !input motion_entity2 from: "off" to: "on" + id: motion_entity2_on + - trigger: state + entity_id: !input motion_entity1 + from: "on" + to: "off" + id: motion_entity1_off + - trigger: state + entity_id: !input motion_entity2 + from: "on" + to: "off" + id: motion_entity2_off +# {% set light_target_var = 'light.test_lamp1' %} +# {{ is_state(light_target_var, 'on') }} actions: - - alias: "Turn on the light" - action: light.turn_on - target: !input light_target - - alias: "Wait until there is no motion from device1" - wait_for_trigger: - - trigger: state - entity_id: !input motion_entity1 - from: "on" - to: "off" - - trigger: state - entity_id: !input motion_entity2 - from: "on" - to: "off" - - alias: "Wait the number of seconds that has been set" - delay: !input no_motion_wait - - alias: "Turn off the light" - action: light.turn_off - target: !input light_target + - choose: + - conditions: + - condition: trigger + id: + - motion_entity1_on + - motion_entity2_on + sequence: + - if: + - condition: template + value_template: "{{ states( 'light.test_lamp1' ) == 'off' }}" + then: + - alias: "Turn on the light" + action: light.turn_on + target: !input light_target + + - conditions: + - condition: trigger + id: + - motion_entity1_off + - motion_entity2_off + sequence: + - if: + - alias: "None of motion sensor are detected" + condition: not + conditions: + - condition: template + value_template: "{{ is_state('binary_sensor.presenza_alta_scala_mansarda_occupancy', 'on') }}" + - condition: template + value_template: "{{ is_state('binary_sensor.presenza_bassa_scala_mansarda_occupancy', 'on') }}" + #- condition: state + # entity_id: !input motion_entity1 + # state: true + #- condition: state + # entity_id: !input motion_entity2 + # state: true + then: + - alias: "Wait for delay set before turn off" + delay: !input no_motion_wait + - alias: "Turn off the light" + action: light.turn_off + target: !input light_target