How to check the state of a device?

Devices "report" and that is a means to "trigger" a rule but what do you do IN-THE-MEAN-TIME when there is no activity and you just want to "check the state" of the device and take an action based on that state.

Case: is that still on, still off; is that still open, still closed, etc.

This is probably out there in multiple specific posts but I'm looking for the best practice in the general case. I'm not talking about being in a rule that just fired by an open trigger and then waiting for a corollary close. I'm talking about a totally different rule that goes and checks a state, or maybe multiple device states.

Is it all about setting a Boolean or a Variable every time a device changes state or is there some other best practice to read the field that HE uses to post that state/status as seen on the Device's page?

Thanks in advance.

You probably do the checking in the rule's actions. Or use the state as the required expression to a RM 5.1 rule

You might get better advice if you share a specific automation you want to do, since there are multiple ways to read device states in a Rule, but in general options include:

  • a conditional action (IF x THEN), where x can be a device state--or any expression, including the state of multiple devices
  • setting a variable to a device attribute (this is an option when you use "set variable")--and then using that variable somewhere else, likely also in a conditional action ... but if that's all you're doing, the former is probably better
  • not directly checking but using a required expression and letting the rule do some checking for you, likely in conjunction with the option to cancel pending actions when the required expression becomes false (assuming this is the only reason you care about the state)

But, again, it's hard to say more without something specific. Rule Machine can do almost anything you want somehow, so these are just general patterns. :smiley:

2 Likes

OK, we probably don't need to take this further.

It was a, "just in case I missed an approach", kind of question and you guys succinctly hit the main means to achieve this in the general case.

I got it. Thank you.