motion light dual NEW test before variable substitution

This commit is contained in:
2025-01-31 18:53:01 +01:00
parent 390b5c5972
commit cb481ad0ec
2 changed files with 64 additions and 21 deletions

View File

@@ -207,7 +207,6 @@
alias: test-pulsante1 alias: test-pulsante1
description: "" description: ""
triggers: triggers:
- trigger: mqtt - trigger: mqtt
topic: "zigbee2mqtt/Pulsante-01" topic: "zigbee2mqtt/Pulsante-01"
payload: "single" payload: "single"

View File

@@ -3,14 +3,14 @@ blueprint:
description: Turn on a light when motion is detected NEW. description: Turn on a light when motion is detected NEW.
domain: automation domain: automation
source_url: https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml source_url: https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml
author: Home Assistant author: Tiziano Trabattoni
input: input:
motion_entity1: motion_entity1:
name: Motion-sensor1 name: Motion-sensor1
selector: selector:
entity: entity:
filter: filter:
device_class: switch device_class: motion
domain: binary_sensor domain: binary_sensor
motion_entity2: motion_entity2:
name: Motion-sensor2 name: Motion-sensor2
@@ -35,6 +35,13 @@ blueprint:
max: 300 max: 300
unit_of_measurement: seconds 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, # If motion is detected within the delay,
# we restart the script. # we restart the script.
mode: restart mode: restart
@@ -45,27 +52,64 @@ triggers:
entity_id: !input motion_entity1 entity_id: !input motion_entity1
from: "off" from: "off"
to: "on" to: "on"
id: motion_entity1_on
- trigger: state - trigger: state
entity_id: !input motion_entity2 entity_id: !input motion_entity2
from: "off" from: "off"
to: "on" 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: actions:
- alias: "Turn on the light" - choose:
action: light.turn_on - conditions:
target: !input light_target - condition: trigger
- alias: "Wait until there is no motion from device1" id:
wait_for_trigger: - motion_entity1_on
- trigger: state - motion_entity2_on
entity_id: !input motion_entity1 sequence:
from: "on" - if:
to: "off" - condition: template
- trigger: state value_template: "{{ states( 'light.test_lamp1' ) == 'off' }}"
entity_id: !input motion_entity2 then:
from: "on" - alias: "Turn on the light"
to: "off" action: light.turn_on
- alias: "Wait the number of seconds that has been set" target: !input light_target
delay: !input no_motion_wait
- alias: "Turn off the light" - conditions:
action: light.turn_off - condition: trigger
target: !input light_target 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