Forgive me if this is documented or has been discussed but I cannot seem to find it.
I have a few automation ideas that would benefit from multiple triggers.
For instance, if I am away, if a window or a door or a motion detector goes off, that would indicate intrusion. I would like to create an automation based on that that would work as an alarm. I have seen the alarm integration and with my code locks, I would just rather use them. Door unlocks by code, alarm is shut off. But, if any of those things trip, then I need to be concerned. I do have sensor groups set up for this. I just want to trip on the âorâ of those for this process. I also have some other things like if a motion sensor trip OR the door opens, turn on the light. That kind of stuff with âorâ for triggers would reduce my automations.
On the other side, I also have an âANDâ need where say if window 1, 2, 3, and 4 are opened, assume I want to open the windows and shut down my heating or air conditioning.
Again, I have looked all over and could not find this.
That is not what I asked. I am asking if multiple triggers are considered an âORâ or an âANDâ and how to change them to the other if I need to.
I can do ORs and ANDs all day in the conditions portion. I need to do this in the trigger section.
You canât. there is no way to do that and it wouldnât really make sense either.
triggers are events that happen at an instance in time. Much like the device they are named after - you pull the trigger and at that instant the gun fires.
If the trigger wasnât an âorâ then there would be any number of triggers âwaitingâ to go off when another trigger happens which doesnât make sense.
any of the conditions to make a trigger conditional will be located in the aptly named âcondition:â section of the automation.
By using correctly configured conditions you can then allow a trigger act like a trigger and use the conditions to check that the conditions are met to run the actions when the trigger fires.
also be aware that conditions in the âcondition:â section of the automation wonât wait to be satisfied either. if the trigger fires the conditions are immediately checked and if the conditions all return false then the automation stops. It then needs a new trigger event before it will again check that the conditions are satisfied.
there are conditions you can use in the actions section to create more condition checks (waits, delays, choose, if-then, etc) to control action flow if needed.
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.