MartinAM
(Martin Adam Martinsen)
May 14, 2024, 8:10pm
1
I am trying to get condition and to work inside blueprint, but I can’t figure out what’s wrong.
Here is my code:
blueprint:
name: Motion-activated Light with Timer and Input Override
description: Turn on a light when motion is detected, use timer to control wait time and Use Input Coverride Condition
domain: automation
# source_url: http://
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
input_entity:
name: Switch Input
selector:
entity:
domain: binary_sensor
device_class: power
timer_entity:
name: Timer
selector:
entity:
domain: timer
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
trigger:
- id: motion_detected
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
- id: motion_unetected
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- id: timer_finished
platform: event
event_type: timer.finished
event_data:
entity_id: !input timer_entity
variables:
switch_input: !input input_entity
action:
- choose:
- conditions:
- condition: trigger
id: motion_detected
sequence:
- service: timer.cancel
target:
entity_id: !input timer_entity
- service: light.turn_on
target: !input light_target
- conditions:
- condition: trigger
id: motion_unetected
sequence:
- service: timer.start
target:
entity_id: !input timer_entity
- conditions:
- condition: and
- conditions:
- condition: trigger
id: timer_finished
- condition: template
value_template: "{{ is_state(switch_input, 'off') }}"
sequence:
- service: light.turn_off
target: !input light_target
Conditions are logically AND by default there is no need to use an explicit And condition unless it is inside an Or or Not condition. If you just want to use it for your own reasons, you need to fix the indentation:
Action block w/And condition
...
action:
- choose:
- conditions:
- condition: trigger
id: motion_detected
sequence:
- service: timer.cancel
target:
entity_id: !input timer_entity
- service: light.turn_on
target: !input light_target
- conditions:
- condition: trigger
id: motion_unetected
sequence:
- service: timer.start
target:
entity_id: !input timer_entity
- conditions:
- condition: and
conditions:
- condition: trigger
id: timer_finished
- condition: template
value_template: "{{ is_state(switch_input, 'off') }}"
sequence:
- service: light.turn_off
target: !input light_target
....
MartinAM
(Martin Adam Martinsen)
May 14, 2024, 8:19pm
3
I got it to work
blueprint:
name: Motion-activated Light with Timer and Input Override
description: Turn on a light when motion is detected, use timer to control wait time and Use Input Coverride Condition
domain: automation
# source_url: http://
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
input_entity:
name: Switch Input
selector:
entity:
domain: binary_sensor
device_class: power
timer_entity:
name: Timer
selector:
entity:
domain: timer
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
trigger:
- id: motion_detected
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
- id: motion_unetected
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- id: timer_finished
platform: event
event_type: timer.finished
event_data:
entity_id: !input timer_entity
variables:
switch_input: !input input_entity
action:
- choose:
- conditions:
- condition: trigger
id: motion_detected
sequence:
- service: timer.cancel
target:
entity_id: !input timer_entity
- service: light.turn_on
target: !input light_target
- conditions:
- condition: trigger
id: motion_unetected
sequence:
- service: timer.start
target:
entity_id: !input timer_entity
- conditions:
- condition: and
conditions:
- condition: trigger
id: timer_finished
- condition: template
value_template: "{{ is_state(switch_input, 'off') }}"
sequence:
- service: light.turn_off
target: !input light_target
MartinAM
(Martin Adam Martinsen)
May 14, 2024, 8:19pm
4
I will test without and statement
MartinAM
(Martin Adam Martinsen)
May 14, 2024, 8:26pm
5
It worked too, thx.
blueprint:
name: Motion-activated Light with Timer and Input Override
description: Turn on a light when motion is detected, use timer to control wait time and Use Input Coverride Condition
domain: automation
# source_url: http://
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
input_entity:
name: Switch Input
selector:
entity:
domain: binary_sensor
device_class: power
timer_entity:
name: Timer
selector:
entity:
domain: timer
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
trigger:
- id: motion_detected
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
- id: motion_unetected
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- id: timer_finished
platform: event
event_type: timer.finished
event_data:
entity_id: !input timer_entity
variables:
switch_input: !input input_entity
action:
- choose:
- conditions:
- condition: trigger
id: motion_detected
sequence:
- service: timer.cancel
target:
entity_id: !input timer_entity
- service: light.turn_on
target: !input light_target
- conditions:
- condition: trigger
id: motion_unetected
sequence:
- service: timer.start
target:
entity_id: !input timer_entity
- conditions:
- condition: trigger
id: timer_finished
- condition: template
value_template: "{{ is_state(switch_input, 'off') }}"
sequence:
- service: light.turn_off
target: !input light_target