Open/close sensor state of currently opened vs. opened/closed

I have a whole house fan automation I set up to precondition on temp inside and outside and then “when any condition below is met” when “Contact sensor: open” on 6 contact sensors.

The idea is as long as anything is open, run the automation to turn the fan on.

The problem is the way the “contact sensor: open” seems to work is only when it detects a change from closed TO open.

It doesn’t look like there’s a way to do anything else with the stock device, but maybe there’s a custom one that can distinguish between “is being opened/closed” and “is currently open or closed”.

Sort of. It is all about when the Routine triggers, by which I mean when it determines whether it needs to perform the actions in the ‘then’ section.

In your Routine a change to the state of any of the contact sensors will trigger it. However a change to the temperatures won’t. Nothing else will trigger it either.

I am guessing that is the issue you are experiencing.

Unfortunately this isn’t something you can deal with in one Routine. You probably need at least three.

  • One to set a flag when any contact sensor is open.
  • One to clear a flag when all contact sensors are closed.
  • One to test for both of your temperature conditions being true and your flag being set, none of them being set as preconditions, and turning the fan on if required.

In practice, ‘set/clear a flag’ really means to use the state of a virtual switch (or a real one) to represent the state of your contact sensors in a way that can be used to trigger a routine.


Graham’s solution is probably the most straightforward way to approach your use case, but I’m not sure it’s what you’re going for.

The difference between “is being opened/closed” and “is currently open or closed” is the difference between a trigger and a precondition in a Routine. You can think of a precondition as a state check i.e. “is this thing open or closed” vs a trigger which is a change of state i.e. “going from open to close or off to on”.

What you described above are all preconditions, the inside temp being at a certain level, the outside temp being at a certain level, and the sensors being in a certain state. So, you have to have a trigger if you want all those to be preconditions.

Perhaps a different approach would be to make the state of the sensors and the outside temp preconditions and then have the inside temp be the triggering event. To do that though, you would need multiple Routines. So:

If Sensor 1 open (precondition)
   Outside temp equal or above X deg (precondition)
   Inside temp equal or above X deg
   Turn on Fan
If Sensor 2 open (precondition)
   Outside temp equal or above X deg (precondition)
   Inside temp equal or above X deg
   Turn on Fan

and so on…

Of course you need a Routine(s) to turn off the fan, but you haven’t mentioned the req’ts for doing that.

If you’re willing to use a 3rd party rules engine that provides more complex logic, then I’d look at You still have the same dilemna of what is your triggering event, but you can likely write the logic in a single rule vs having to do multiples.


Thank you both for your suggestions. I think the virtual switches is probably the best way to go here though it adds many more moving parts and I have played with virtual switches before that get into the wrong state so there’s some ongoing maintenance too with that option. I guess an app here could possibly do this more robustly.

Bruce, your shortcut seemed like a good option until I played with it a bit and you’re right that I really need everything to be a precondition.

I’ll keep fiddling. Thanks gentlemen.

1 Like

I think it is important to recognise that the trigger is an extra thing.

Consider a Routine that tests for contact sensor P1 being open as a precondition, and all of C1, C2 and C3 being open as the conditions.

What that means is: if one of C1, C2 or C3 has just changed state from open to closed or closed to open then if P1, C1, C2 and C3 are now all currently open then do something.

The Routine can probably also be executed manually via the API, in which case the current states are all that matter.

What it doesn’t mean is: if P1 is currently open and all of C1, C2 and C3 have just changed from closed to open then do something.

Some users do think that.