Triggers defines when your conditions will be checked.
Triggers are always OR
Conditions are AND unless you explicitly add an OR condition.
In your case, door opening OR windows opening are your triggers, you away is the condition to run the automation.
The automation will never run while you are at home, and won’t check if you are away until a door or window is opened.
For this case you can have a state trigger checking all of your windows (OR) changing states to “opened”, then in your conditions you should check if all windows are open (AND).
As mentioned by others, you cannot logically AND triggers.
One way to fulfill your “four windows open” requirement is by using a Template Trigger.
alias: example
description: Turn off climate system when all four windows are opened
trigger:
- platform: template
value_template: >
{{ expand('binary_sensor.window1', 'binary_sensor.window2',
'binary_sensor.window3', 'binary_sensor.window4')
| selectattr('state', 'eq', 'on') | list | count == 4 }}
condition: []
action:
- service: climate.turn_off
target:
entity_id: climate.main
If condition are always AND why is there and “AND” condiftion where you can add specific condition test ?
My need is to set a boolean to “away” when both me and my wife are not home.
So I was also looking for an AND trigger, but ended up with this.
Do I need to use the AND condiftion ? or just 2 conditions ?
Another question :
how does the time “for” works ?
let assume this scenario:
I leave the home at 7h (the automation should not go to the end)
then, my wife leave the home 1h hour after me, at 8h (both condition should match, after she’s been away for 10min or more) then the action should be activated.
Whilst you can’t have true ‘AND’ triggers, you can chain multiple triggers together, but the order of execution would determine whether or not the automation fires, such as:
description: ""
mode: single
trigger:
- platform: state
entity_id:
- binary_sensor.lumi_lumi_motion_ac02_iaszone_2
to: "on"
condition: []
action:
- wait_for_trigger:
- platform: state
entity_id:
- light.all_kitchen_light_group
to: "on"
In this case, motion has to be detected, andthen some lights turned on. You could put a timeout on the wait_for_trigger if the lights are not turned on within a specified period.
If you mean a trigger template then i don’t think thats how they work.
if I reference 2 entities and combine them with an AND, then iirc, whenever either entities state changes, the trigger template will fire, and the state of both entities at that time will be evaluated. So its not the smae as two triggers firing at once.
If you create a template that has an ‘and’ in the logic then it means that it needs both parts to be true before the template (and ultimately the trigger) turns true.
example:
{{ is_state('binary_sensor.sensor_1', 'on') and is_state('binary_sensor.sensor_2', 'on') }}
Since the logic is ‘and’ this will only return true when both sensors are ‘on’.
the template doesn’t need to look for a state change on both entities at the same instant. it just needs to evaluate both entities at a particular moment (which technically is when either entity’s state changes) and if they are both ‘on’ then the logic is satisfied and the template evaluates to true. That in turn sets the trigger to true and the trigger fires.
Having to resort to template triggers or repeating yourself in conditions to do logical ‘and’ is a UI stink, classic case of “you’re holding it wrong”. This should be high on Home Assistant priority list to resolve so conditions, triggers, and actions have a more uniform and intuitive interface.
That said, template triggers (as @finity examples) seem to be the best workaround until HA team gets around to brushing up the UI.
I came to this topic because I have stairs, then a landing, a right angle, then a corridor. So this needs at least 3 motion sensors (good thing they’re 3€ each)
Obviously, the lights must turn on when any motion sensor detects someone.
Then they must remain on as long as there’s someone around.
After the occupants are gone, there’s the usual timer, then the lights turn off.
Battery powered motion sensors report “occupancy” once when they detect motion. Then they report “clear” when they no longer detect motion. Between the two, they don’t waste their batteries reporting the same state over and over again.
Thus step 2 requires a trigger on “all sensors report occupancy: clear”.
But that does not require that triggers be logically AND…
What you have described can be accomplished with a State trigger based on a Group, a Template trigger (see Post 17), or a State trigger and state condition that contain all three sensors (see Post 12).
I see “When DM Escalier changes from any state to Clear for 1:00”. This has no meaning. I assume it means “When DM Escalier changes from any state to Clear and remains at state Clear for 1:00”. If this is the intended meaning, then it does not work: when I exit the stairs, wait for the motion detector to clear, then quickly return to the stairs, it turns off the light instead of restarting the automation as it should, since the automation’s starting trigger should be… well, triggered.
Default mode for automations is single. If you try to retrigger it while it’s still in the 1 minute timeout for clear, nothing will happen because the automation is still running.
If you want your automation to retrigger, all you have to do is add mode: restart at the bottom of the automation and job done.
There’s an option to do this in the UI too, but I can’t remember where it is or what it’s called.