# A flow to identify inactive sensors (values) / unavailable devices

**URL:** <https://community.homey.app/t/a-flow-to-identify-inactive-sensors-values-unavailable-devices/85808>\
**Category:** Questions & Help\
**Created:** [August 2, 2023, 9:45am UTC](https://community.homey.app/t/a-flow-to-identify-inactive-sensors-values-unavailable-devices/85808 "2023-08-02T09:45:40Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![albert\_bodden](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/albert_bodden/32/80977_2.png) [@albert\_bodden](https://community.homey.app/u/albert_bodden)\
**Post date:** [August 4, 2024, 8:41pm UTC](https://community.homey.app/t/a-flow-to-identify-inactive-sensors-values-unavailable-devices/85808/21 "2024-08-04T20:41:09Z")

</div>

Good afternoon and thanks for the help in advance! I (think) I’ve figured out most of the steps but keep getting this error. Any help would be appreciated!

 ![error](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/b/bbe7c554c101757ae2e2f4e871a878fdebcb59db.jpeg)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [August 4, 2024, 8:59pm UTC](https://community.homey.app/t/a-flow-to-identify-inactive-sensors-values-unavailable-devices/85808/22 "2024-08-04T20:59:35Z")

</div>

Please post the code from the Homeyscript card, Albert.  
And welcome to Homey forum.

---

<div class="post-metadata">

**Author:** ![albert\_bodden](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/albert_bodden/32/80977_2.png) [@albert\_bodden](https://community.homey.app/u/albert_bodden)\
**Post date:** [August 4, 2024, 9:17pm UTC](https://community.homey.app/t/a-flow-to-identify-inactive-sensors-values-unavailable-devices/85808/24 "2024-08-04T21:17:53Z")

</div>

@Peter_Kawa Thanks for the assist. Here’s the code:

```auto
// Check last_update status. Argument: inactive time (in seconds):

const INVALIDATE_AFTER = args[0]; // xmpl: 86400 = 1 day (24h)

const invalidatedDevices = [];
for (const device of Object.values(await Homey.devices.getDevices())) {
  if (! device.capabilitiesObj) continue;
  let count = 0;
  for (const capabilityObj of Object.values(device.capabilitiesObj)) {

    // Exclude by app names virtual devices and other app devices
    // (find correct app names via https://tools.developer.homey.app/tools/devices and look for "Driver")
    if (device.driverUri.match('vdevice|DeviceCapabilities|chronograph|betterlogic|devicegroups|callmebot|netscan' )) continue;
    // Exclude by (parts of) device name
    if (device.name.match('^se|^pr|TST|z_|z |z. |IR|rris|eboo|rada|KNM|Timeline|#1|#0|ESP|esp|TV C|TV S|iffu|Unav|Wekk|OUD|OLD|Peter|Custom|Afval|LEDs')) continue;

    if (! capabilityObj?.lastUpdated || (Date.now() - new Date(capabilityObj?.lastUpdated) > INVALIDATE_AFTER * 1000)) {
        count++;
        }
  }
  if (count && count === Object.keys(device.capabilitiesObj).length) {
    invalidatedDevices.push(device.name);
  }
}

// When there are matching sensors
if ( invalidatedDevices.length != 0 ) {
  // Create / update HomeyScript variable
  await tag('InvalidatedDevices', invalidatedDevices.join(', \n'));

  // Send Timeline notification
  Homey.flow.runFlowCardAction({
          uri: 'homey:manager:notifications',
          id: 'create_notification',
          args: {
            text: "\nDevices without updates for " + INVALIDATE_AFTER / 3600 + " hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days:\n" + invalidatedDevices.join(', \n')
          },
        });

  console.log("Devices without updates for " + INVALIDATE_AFTER / 3600 + " hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days: \n" + invalidatedDevices.join(', \n'));
}
  return("Devices without updates for " + INVALIDATE_AFTER / 3600 + " hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days: \n" + invalidatedDevices.join(', \n'));

// When there's no matching sensor
if ( invalidatedDevices.length == 0 ) {
  // just report "None"
  // Create / update HomeyScript variable
  await tag('InvalidatedDevices', 'None');

  // Send Timeline notification
  Homey.flow.runFlowCardAction({
          uri: 'homey:manager:notifications',
          id: 'create_notification',
          args: {
            text: "\nDevices without updates for " + INVALIDATE_AFTER / 3600 + "hrs: None"
          },
        });

  console.log("Devices without updates for " + INVALIDATE_AFTER / 3600 + "hrs: None" );
}

return ("Devices without updates for " + INVALIDATE_AFTER / 3600 + "hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days: None" );

// Original script by Robert Klep
// https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/9

```

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [August 4, 2024, 10:41pm UTC](https://community.homey.app/t/a-flow-to-identify-inactive-sensors-values-unavailable-devices/85808/25 "2024-08-04T22:41:50Z")

</div>

Some things have changed in Homeyscript;  
Please get udated scripts here:

> [@A script to check sensor last update](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/39):
>
> As there is for some time options to see Lastseen timestamp for Zigbee devices, here is the script for Zigbee devices only, which might be more accurate for Zigbee devices. Thanks @Caseda for your overview script wink Version 0.3 - updated for HomeyScript v. 3.5.1 Version 0.3b - fixed for THEN card (returning TEXT value), primary use-better use is for AND card though Version 0.4 - added option to filter out routers and/or end devices // Version 0.4 // Script checks LastSeen property of Zig…

[Previous page](https://community.homey.app/t/a-flow-to-identify-inactive-sensors-values-unavailable-devices/85808.md?page=1)
