I apologize for the following post. It is very long. The issue is complicated.
I use a C-7 Hub Mesh and Z-wave devices to control the physical environments in rooms of my house that I use for my Indigo Snake breeding operation. If lights stay ON when they are supposed to be OFF, or if heaters/air conditioners are in the wrong state, there is the potential that I could lose animals, eggs, and an entire year of income or more if I don't catch it in time.
Over the past three years, I estimate that I've spent 1% of my rule-writing time on basic rules to control device states in the manner that I need, and 99% of my time writing much more complicated rules to achieve reliability of those device states. So far, although I have been able to improve the reliability of my control immensely, I haven't been able to achieve as reliable a setup as I know is possible. What's missing as I see it, could be solved with a minimal change to some logic within Rule Machine (or maybe I'm just missing something).
The problem arises from the fact that radio-based automations are never perfect. Sometimes a hub can issue a command, and the device doesn't receive the command. Sometimes the device receives the command and carries it out, then sends a response back to the hub telling the hub that the command was carried out, but the hub doesn't receive the response (called an "ACK" as I understand it). There are other scenarios that can cause this. The bottom-line is that a hub sometimes thinks that a device is ON when it is OFF, and vice-versa.
The following is stripped-down code to show an example of the best I seem to be able to do so far:
In the first image is simple code showing that instead of just turning a heater switch ON, I run a rule action to do that.
In the second image is a rule action that runs a Repeat Loop which turns the heater switch ON and waits for a global variable called "ValidState" to indicate that the switch was actually turned ON correctly (ValidState = 1).
In the third image is code from a third rule that sets ValidState to 1 when it is triggered by the event of the switch actually turning ON. ValidState = 0 is the situation for Heater OFF btw.
These three rules (in reality it takes at least four or five rules to do it properly and a lot more code than I'm showing here) prevent 99.9% of the logic-based failures that I am likely to encounter with only a simple ON/OFF rule.
The remaining problem lies in the meaning to Rule Manager of the event trigger "EggRm Heater turns ON." This event fires when the state of the heater changes from OFF to ON. If the hub thinks that the heater is ON (but by error it is actually OFF), when my rules call for the heater to turn ON, the heater may turn ON but the repeat loop will go on indefinitely because the hub thought the heater was already ON and therefore won't detect a change of device state. The only sure-fire method to verify that the heater is actually ON in this circumstance is to turn it OFF, detect a valid OFF state, and then turn it back ON again to detect a valid ON state.
What is needed is a "Heater Reports ON" event, not a "Heater Turns ON" event. I've seen log entries like that from some Z-wave devices. Most Z-wave devices ACK what I call a "duplicate" command. That is, if the device is sent a command to turn ON and the device is already ON, the device will still send back a response to the hub either "EggRm Heater is ON" or "EggRm Heater reports ON." The problem is that I can't find any way to trigger an event based on the ACK to the duplicate command that I know the hub is receiving.
I thought I had found my holy grail when in searching, I stumbled upon the "custom" event trigger for switch changes. With that event, the language used is "device reports ON."
Unfortunately, with the testing I've done, even though the devices are actually reporting their state following a duplicate command (as can be seen in the hub logs), the custom switch event seems to have the same issue that I consider a logical failure: "device reports ON" actually means "device reports ON and it was changed to ON from OFF."
There is also a digital switch event that can be accessed for devices on the Hubitat hub, but it seems to have the same shortcoming.
To truly know the state of a device from within a rule following a command being issued to the device (including a Refresh command btw) the writer of the rule has to test for the report of the device state sent by the device. That means there has to be an event trigger that responds to the ACK that good devices send when they are commanded to go to a state that they are already in.
Either I'm missing something or this is a serious logical failure in Rule Manager logic. If "device reports ON" actually meant that, my entire automation setup would be more reliable, would give me far fewer false alarms, and it would take less code to get there.