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

@@ -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