Rule for contact sensor alert not sending text and email


I have a rule set up in rule machine that is supposed to alert me if a contact sensor is left open and the thermostat is running. I can't seem to see why it isn't sending alerts. When I open the door, it is supposed to wait 5 minutes and then send an alert if the door is still open. When I check the rule, it goes from False to True but never sends the alert. Any help is appreciated to see if there is something I am missing. I have a screenshot of the rule below. Thanks!

Remove the contact sensor from the required expression.

The required expression must go true before the rule can be triggered. What's likely happening is that the contact sensor is left open and that fulfills the required expression, but because the state doesn't change to "open" again, the rule is not actually triggered.

You'll also need to update the actions.

IF(contact open)
  Wait 5 min

The wait will be cancelled if the contact closes before the 5 min are up. If I'm not mistaken, then "cancel pending actions" in the required expression will also cancel the wait if the HVAC mode changes.

A required expression prevents triggering if false when (or right before, as I like to think of it--i.e., states resulting from the trigger do not come into play) the trigger event happens. So, in your case, this means your trigger effectively only captures when the contact sensor is closed, among other things (a change in state when open would have to be to a closed state).

There are some other issues, notably an apparent confusion between thermostat mode and thermostat operating state. If you want to know if/how it's currently running, the latter is what you want.

I would re-think the flow of this rule a bit. If you don't care whether the thermostat starts running first or the contact sensor gets opened first (i.e., you want notifications no matter what the order, just as long as it happens), I think you can simplify quite a bit, including removing any required expression.

From what you described, something like this might work instead:

Trigger events:

Thermostat operating state is heating OR
Thermostat operating state is cooling OR
Contact sensor deck door opened

Actions to run:

Wait for expression: ((Thermostat operating state is heating OR
   Thermostat operating state is cooling) AND 
   Contact sensor deck door opened) --> duration: 0:05:00
Notify: "Deck door open while thermostat running at %time% on %date%"

There is probably a more elegant way to write this, but it seems like it should at least get the job done. :slight_smile:

If not: the #1 thing you. can to to do to troubleshoot when a rule (or any app) isn't working correctly is to enable logging, then look at them (or share them here if you need help) to figure it out.

Good luck!

Thanks to both of you for the responses. @bertabcd1234, yes I want to know the mode - I want it to trigger if the thermostat isn't "off".

The strange thing is that my rule was working under the old rule machine and then it just stopped (this was a while ago). That is why I was trying to move it to the new one. I don't really create a new rule that often so it takes me a bit to remember what I did before. Anyway, after changing it to the rule below, it works but it only sends out an alert once. What would I need to add to have it repeat every 5 minutes until the sensor is closed? I thought there was an toggle button option to repeat, but I think that might have been a different app.

First, it should be noted that the rule you wrote above is different from the one I suggested. If that is not what you want, I suggest re-writing it as above. Because of these differences, the outcome will be different in at least a couple ways:

  1. Nothing will happen if the sensor is already open and the thermostat starts running (assuming that is what you want; more below).
  2. If your specified expression is true (after the rule triggers), the notification will be sent with a five minute delay, regardless of what might happen to the value of that expression in the meantime--e.g., you'll still get it if the sensor closes.
  3. You are looking at the mode of the thermostat and not the operating state, which could be what you want but won't tell you if it's actually running. Most people seem to want the operating state, though I suppose I could understand either.

As for the repeat, you are probably thinking of a different app (Notifications?). But you can still do this in Rule Machine. If you go back to my suggested rule, you would want to surround the "Notify" action with "Repeat While (expression)" and "END-REP." So something more like:

Wait for expression: ((Thermostat operating state is heating OR
   Thermostat operating state is cooling) AND 
   Contact sensor deck door opened) --> duration: 0:05:00
Repeat While ((Thermostat operating state is heating OR
   Thermostat operating state is cooling) AND 
   Contact sensor deck door opened) 
Notify: "Deck door open while thermostat running at %time% on %date%"

(You can re-use your existing conditions when creating the second expression, so you only have to create those once, though you will have to build the expression both times. Or you could use NOT idle instead of cooling OR heating if that reflects the possibilities of your device; many can also do fanOnly and might not be something you want to capture with the latter.)

OK, I was wrong this is not working correctly. It is triggering the alert now whether or not the door is left open, meaning just by opening it, it is delaying by 5 minutes, and then sending alerts, even if it's closed within that 5 minutes. I'm missing the "cancel" portion apparently.

Yes, that was my point 2 above and one reason I wrote the rule the way I did (note also the different trigger for this event, even if you don't care about the others as I assumed).

Thanks. I'll take a look at this again in a bit with what you put out there.

For the third point, from what I can see, the state is cooling, heating, etc., while the mode is off, auto, heat, cool, etc.

Unless we are airing out the house, in which we turn off the thermostat, I want to get an alert regardless of whether it is cooling or heating if the thermostat is on.

For anyone interested, this is what I ended up with. Thanks again to everyone pointing me in the right direction.

1 Like