Exactly. That custom driver shoves OFFLINE into a field it shouldn't - that's why other parts of hubitat don't recognize it, as that field should never have had that value in the first place...
I think the best, most "standard" solution would be to fix the driver so switch reports on or off as it should, then you could add a custom attribute to report the online/offline state however you want (not sure a standard capability fits with that, but one of those could certainly work too if there's one that's appropriate).
But I'm assuming you didn't write this driver, and perhaps you don't feel like (or know how to) modify it yourself. In the meantime, you could probably use "switch changed" as a trigger in RM and in the actions do a test for a custom attribute (it's an option--not the standard switch capability attribute) to see if "switch" is "OFFLINE", but that's just a guess. This driver is likely to cause problems other places, however (e.g., as a switch tile on a Dashboard), so I'd really recommend fixing it in the long term.
Got the message. I will have an update out by the end of the month. Of course, if the device is off-line, then the state is not necessarily valid and a rule may do the wrong thing.
Changes coming:
Add attribute commsError (true/false).
Add routine to automatically recover comms (5 tries only) on commsError.
Clear comms error on successful receipt of message.
SoapBox: It seems it would be good to have a state of offline for a device switch. You can not set it to that state; however, in rules, such a state needs to be known.
I applied your updates and they worked. Thank you. But I did spend time trying to figure out why after selecting the commsError attribute I was not seeing the "Select enum value (text)" field to be able to type either false or true.
You have to first select the Switch attribute and then select again commsError so the "Select enum value (text)" field becomes available. Seems to be a bug.
For the Kasa HS110, can I set the Refresh Interval to be 30 seconds?
In the Devices settings page the smallest setRefreshInterval is 1 minute:
The only way that you can know if a device is offline is if it doesn't perform a routine function. There is no other way for the system to know whether it is online or not. So, in the case of energy monitoring plugs, this might be possible if there is a load on the plug that varies enough to cause it to report. But you would have to build a custom driver to have a function like that. Do you understand that your devices don't routinely "check-in" with the hub that frequently, in the case of battery devices, in order to save power. Any type of forced polling is going to cause your batteries to drain much, MUCH quicker.
Within the driver itself, the communications error is detected and handled automatically, as follows:
On initial installation, the attribute is null
Once a command is set, the attribute will be set (eventually) to true or false
if the command resulted in a valid response, it is set to false immediately
if the command fails, it will be set to true after (up to) five retries of the failed command.
Once the attribute is true, it will remain true until a command executes successfully and results in a valid response. It will then be set to false.
if the attribute is true, there is nothing you can do automatically to clear the error (other than try another refresh). Troubleshooting may be required.
I can't and won't address rule machine; My interface ends at the device driver. However, when the attribute is true, something is wrong, usually,
The device's IP has changed
The device is no longer powered
There is some intermittent error that may clear by itself.
(unusual) the hub is at fault and requires reboot.
The user will have to troubleshoot. Some checks:
Try to control the device in the Kasa App. If you can't, the device is unplugged or failed.
Check the IP address on the device's page and your router or run the hubitat application. (running the application install or list devices updates the IP on the existing devices.)
Go to the device's page, turn on debug logging. Open a logging page and try to control the device. If you do not see anything, then try rebooting Hubitat.
It is STRONGLY recommended that you use static IP addresses for devices.