How to monitor device still being active?

Before we used to have the ability to say “if a sensor hasn’t responded in x time” flow card, but that seems gone, now. Some devices in our home are pretty crucial, and sometimes they stop responding for a plethora of reasons. Sometimes it’s wifi related, other times it’s Zigbee, or what have you.

But I’d like to ensure that my temperature sensors have updated in at least an hour. My current idea is to have a timer that starts counting down, that you reset to an hour every time that sensor updates a value. But that’d be a lot of unique timers and values to keep track of.

Does anyone have a neater way of doing it?

…eg. I’m using Advanced flows and checking different devices types differently

2 Likes

I think the function : If a sensor hasn’t responded in x time, is still available (at least on my pro 2016/2019).
Home → scroll down : A device hasn’t reported in.

Homey Pro (early 2023) has this function removed as it was a pretty heavy function and pretty unreliable.

Athom has talked about re-adding it, but “per device” and not a “for every device in a zone”.
For now it is just talk, have seen no evidence of it yet.

1 Like

Yeah that triggercard caused flows to get disabled while ‘started too many times’ (Classic Pro 2019).
The mentioned script is a much better way imho, also for the 2023

Thank you! That’s an excellent idea. I’ll be using this.

I took the liberty to rewrite your code to more efficiently and in a more readable manner to check for unresponsive devices:

const reportThresholdMs = 60 * 60 * 1000
const reportThreshold = new Date(Date.now() - reportThresholdMs);

let devices = await Homey.devices.getDevices();

function isRelevant(device) {
  if (device.class.match(/sensor|camera|thermostat/i)) {
    return true;
  }

  return false;
}

function isUnresponsive(device) {
  let unresponsive = true;

  // So long as one capability is updated after reportThreshold,
  // the device is considered responsive.
  Object.values(device.capabilitiesObj).forEach(capability => {
    let lastUpdated = new Date(capability.lastUpdated ?? 0);
    if (lastUpdated > reportThreshold) {
      unresponsive = false;
    }
  });
  return unresponsive;
}

let devicesToCheck = Object.values(devices).filter(isRelevant);
let unresponsiveDevices = Object.values(devicesToCheck).filter(isUnresponsive);

let unresponsiveDevicesNames = Object.values(unresponsiveDevices).map(device => device.name);
log(unresponsiveDevicesNames);

The last two lines is just an example of how to retrieve the list. the “isRelevant” function is barebones, but shows how you can implement more checks on matching. I’ll start the implementation of actually using this tomorrow.