Help modifying an app code

I would like to use the follow app to detect a power failure but instead of using a canary bulb. I would like to use the voltage value from a Zooz ZEN04 smart plug. Which reports voltage.
Here is the app code

line 19 I know I need to change to capability.voltageMeasurement
Now I am not sure were I would need to look for zero volts or even how to do that. I am guessing around line 48.
Thanks for your help.

I am not sure this is what you will want to do... depending on what the rest of the app does to handle innacitvity (I'll admit I haven't read all the code). If power or connectivity to a device is lost, the Current States or Attributes will not normally be updated to reflect this, they are often only updated when the device reports back to HE, i.e. when connectivity is available, so during periods where connectivity is lost, the current state will remain as the last state that was reported.

I could be misinterpretting the code or your intentions here...

I suspect what you may be after is an app like @bertabcd1234 's Device Activity Check:

1 Like

Good point. I wasn't thinking about that.

What you're expecting is that in the event of a power failure, your ZEN04 will report a voltage of zero. As @sburke781 explained, this will not work, because the ZEN04 will be unpowered during a power failure.

However, there are several alternative methods to let the hub know that there has been power failure, all of which make use of devices that are battery powered.

  1. You can make a Power Monitor - costs about $15-25 to put it together. This thread has a number of examples.
  2. You can use a Hubitat-paired thermostat like z-wave models from GoControl or Honeywell. These can be powered by both the HVAC transformer and batteries. When A/C power is lost, the thermostat will report it is no longer on "mains" power, or will report it is on "battery" power. These thermostats cost about $50-100.
  3. You can use a Ring z-wave range extender. These are plug-in devices that have a built-in battery backup. They also report when there's a loss of mains power. These cost about $25.
5 Likes