lidans5
(lior)
January 4, 2023, 4:18pm
1
Hi
I need your help, I want that if no presence is detected in both sensors the auto. will work, but it doesn’t what am I doing wrong:
alias: First floor no presence
description: turns off everything
trigger:
- type: no_motion
platform: device
device_id: 4c06412581555ce62259f274706a3922
entity_id: binary_sensor.presence_35
domain: binary_sensor
for:
hours: 0
minutes: 30
seconds: 10
- type: no_motion
platform: device
device_id: b0cb353a1e97450b69344bbfc49e9144
entity_id: binary_sensor.presence_36
domain: binary_sensor
for:
hours: 0
minutes: 30
seconds: 0
condition:
- condition: state
entity_id: input_boolean.shabes_mode
state: "off"
- condition: and
conditions:
- condition: state
entity_id: input_boolean.away_mode
state: "off"
action:
- service: light.turn_off
data: {}
target:
entity_id:
- light.living_room
- light.kitchen
- device_id: e01642003e63a54797b6658a43efaa4d
domain: cover
entity_id: cover.big_blinds
type: set_position
position: 0
mode: single
So what I read is that if either trigger one or trigger two applies it will act
First of all the conditions are wrong or odd… below the ‘and’ I would expect at least more than one condition
… I did not look at the action … what does your ‘trace’ say?
example ‘and’
condition: and
conditions:
- condition: state
entity_id: device_tracker.abc
state: home
- condition: state
entity_id: device_tracker.xyz
state: away
You need to mirror the triggers in your condition section, so that only the last trigger to occur will execute the actions. As @vingerha commented, your and
condition was not set up correctly, however it isn’t necessary in this configuration.
alias: First floor no presence
description: turns off everything
trigger:
- type: no_motion
platform: device
device_id: 4c06412581555ce62259f274706a3922
entity_id: binary_sensor.presence_35
domain: binary_sensor
for:
hours: 0
minutes: 30
seconds: 10
- type: no_motion
platform: device
device_id: b0cb353a1e97450b69344bbfc49e9144
entity_id: binary_sensor.presence_36
domain: binary_sensor
for:
hours: 0
minutes: 30
seconds: 0
condition:
- condition: state
entity_id:
- binary_sensor.presence_35
- binary_sensor.presence_36
state: "off"
for: "00:30:00"
- condition: state
entity_id:
- input_boolean.shabes_mode
- input_boolean.away_mode
state: "off"
action:
- service: light.turn_off
data: {}
target:
entity_id:
- light.living_room
- light.kitchen
- device_id: e01642003e63a54797b6658a43efaa4d
domain: cover
entity_id: cover.big_blinds
type: set_position
position: 0
mode: single
thanks and on the condition part… this setup is new to me, is this also an ‘and’ by nature?
The default behavior is and
, but that can be modified using the match
variable as shown in the State Condition docs
1 Like
lidans5
(lior)
February 28, 2023, 3:53am
6
thank you (sorry for the late response)
still doesn’t work, what am I doing wrong:
alias: First floor no presence
description: turns off everything
trigger:
- type: no_motion
platform: device
device_id: 4c06412581555ce62259f274706a3922
entity_id: binary_sensor.presence_35
domain: binary_sensor
for:
hours: 0
minutes: 3
seconds: 10
- type: no_motion
platform: device
device_id: b0cb353a1e97450b69344bbfc49e9144
entity_id: binary_sensor.presence_36
domain: binary_sensor
for:
hours: 0
minutes: 3
seconds: 0
condition:
- condition: state
entity_id:
- binary_sensor.presence_35
- binary_sensor.presence_36
state: "off"
for: "00:03:00"
- condition: state
entity_id:
- input_boolean.shabes_mode
- input_boolean.away_mode
state: "off"
action:
- service: light.turn_off
data: {}
target:
entity_id:
- light.living_room
- light.kitchen
- device_id: e01642003e63a54797b6658a43efaa4d
domain: cover
entity_id: cover.big_blinds
type: set_position
position: 0
mode: single
is there any difference i’m missing ? (changed it to 3 min. so it will be easier to check if it works…)
Troon
(Troon)
February 28, 2023, 8:36am
7
You can’t use for
in a state condition, only in a trigger (docs ).
I think you’ll need a pair of template conditions as well to check the times. Something like this (with the trigger section cleaned up to remove all the device
cruft, although yours is functionally fine):
trigger:
- platform: state
entity_id:
- binary_sensor.presence_35
- binary_sensor.presence_36
to: "off"
for: "00:03:00"
condition:
- condition: state
entity_id:
- binary_sensor.presence_35
- binary_sensor.presence_36
state: "off"
- "{{ (now()|as_timestamp - states['binary_sensor.presence_35'].last_changed|as_timestamp(0)) >= 180 }}"
- "{{ (now()|as_timestamp - states['binary_sensor.presence_36'].last_changed|as_timestamp(0)) >= 180 }}"
- condition: state
entity_id:
- input_boolean.shabes_mode
- input_boolean.away_mode
state: "off"
Change the 180 to the number of seconds you need — should match the for
in the trigger. Obviously, include your existing action
section too .
This triggers when either sensor has been off for 3 mins, but only continues through the conditions if both are off and have not changed for at least three minutes.
Troon
(Troon)
March 1, 2023, 11:27am
9
That really doesn’t give me much to go on. In what way does it “not work”? Are there any traces showing triggers and condition blocks?
Can you put this in the Template Editor and let me know the result?
{{ now() }}
{{ utcnow() }}
{{ now()|as_timestamp }}
{{ utcnow()|as_timestamp }}
{{ states['binary_sensor.presence_35'].last_changed }}
{{ states['binary_sensor.presence_35'].last_changed|as_timestamp(0) }}