# A script to check sensor last update

**URL:** <https://community.homey.app/t/a-script-to-check-sensor-last-update/63142>\
**Category:** Questions & Help\
**Tags:** homeyscript\
**Created:** [April 29, 2022, 7:44am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142 "2022-04-29T07:44:44Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [April 11, 2023, 11:19pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/21 "2023-04-11T23:19:17Z")

</div>

> [@JeeHaa](#):
>
> Use it with an AND Homeyscript card:
> 
> ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/2/b22e3dc153349d8818e098366d1d535857c95d64.png)

👍

\<_nitpicking mode_\>  
If you like, you can use it without the homeyscript tag, with the THEN card “Run code with Argument and return Text-tag”.  
You can adjust the threshold value a bit easier, or even use a variable for that,

 ![Screenshot from 2023-04-12 01-16-52](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/4/047bc8217e1894196dca83739d025b10eb5dcba9.png)

.

change these lines:

```auto
//GetDevicesNotReporting with argument [time in seconds]
const NotReportingThreshold = args[0]; // Trigger when not reported in the last x secs

//await tag('DevicesNotReporting', DevicesNotReporting.join(',\n'));
return (DevicesNotReporting.join(',\n'));

```

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [April 12, 2023, 9:39am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/22 "2023-04-12T09:39:51Z")

</div>

Peter what about this one, seems to be working better for me … it checks now if ANY capability has been updated and seems the time-date error is gone for me and the results are much more relevant.

@JeeHaa maybe it will help also with lights problem you mentioned but not sure how it behaves if user actually change the capability himself (so not the device by user/app etc.)

Latest update - [A script to check sensor last update - #25 by Sharkys](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/25)

---

<div class="post-metadata">

**Author:** ![JeeHaa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeehaa/32/29849_2.png) [@JeeHaa](https://community.homey.app/u/JeeHaa)\
**Post date:** [April 12, 2023, 2:17pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/23 "2023-04-12T14:17:56Z")

</div>

I am pretty sure the returned values are correct, some devices just don’t update as frequently on Homey.

However, I found a workaround to “poll” Lights: just send an On/Off command that is identical to its current state + using a Try/Catch. Effectively nothing changes, but the lastUpdated time gets updated.

```auto
//GetDevicesNotReporting
let NotReportingThreshold = 60; 
if (args[0]){ let NotReportingThreshold = args[0] }
let DevicesNotReporting = [];

let devices = await Homey.devices.getDevices();
for (const device of Object.values(devices)) {

  // Filter devices to check
  //if (device.driverUri.match('vdevice')) continue; // Exclude Virtual Devices
  if (!device.name.match(/lamp|^pc|plug/i)) continue; // Include by device name
  //if (!device.class.match('light|socket')) continue; // Include device types
  //if (device.class.match('sensor|button|remote|socket')) continue; // Exclude device types
  //if (!device.name.match('Plug JH')) continue; // Include by device name

  // Any capability updated recently? Set LastSeen to most recent update.
  IsReporting = false
  LastSeen = 1000000
  for (const capabilityObj of Object.values(device.capabilitiesObj)) {
    let lastUpdated = new Date(capabilityObj.lastUpdated)
    let timeSinceReport = Math.floor((Date.now() - lastUpdated)/1000/60) // Minutes since last update
    if (timeSinceReport < LastSeen){LastSeen = timeSinceReport }
    //log('LastUpdated: '+ device.name + ' ' + capabilityObj.id + ' ' + timeSinceReport) + 'min')
    if (timeSinceReport < (NotReportingThreshold)) { IsReporting = true }
  }

  // Add to list if not reported 
  //DevicesNotReporting.push(device.name + ' [' + LastSeen + 'm]');
  if (!IsReporting) {
    // Try to send command to wake up device if supported
    if (device.class === 'light' || device.virtualClass === 'light') {
      try {
        log('WAKE: ' + device.name + ' - ' + device.class + ' - ' + device.virtualClass + ' [' + LastSeen + 'm]')
        await device.setCapabilityValue('onoff', device.capabilitiesObj['onoff'].value)
      } catch {
        DevicesNotReporting.push(device.name + ' [' + LastSeen + 'm]');
        log('FAIL WAKE: ' + device.name + ' - ' + device.class + ' - ' + device.virtualClass + ' [' + LastSeen + 'm]')
      }
    } else {
      DevicesNotReporting.push(device.name + ' [' + LastSeen + 'm]');
      log('NOK: ' + device.name + ' - ' + device.class + ' - ' + device.virtualClass + ' [' + LastSeen + 'm]')
    }
  } else {
    log('OK: ' + device.name + ' - ' + device.class + ' - ' + device.virtualClass + ' [' + LastSeen + 'm]')
  }
}

// Output for script AND card
await tag('DevicesNotReporting', DevicesNotReporting.join(', '));
return DevicesNotReporting.length != 0;
//return DevicesNotReporting

```

This works fine for disconnected lights ("Catch’ gets executed as expected), but unfortunately my Tuya Plugs give an unexpected result. If a plug is removed from the wall socket this command still succeeds after 5s, and the LastUpdated time even updates (reported to Athom). ☹

Can anyone test with their plugs if they throw an error as expected when disconnected from power?

---

<div class="post-metadata">

**Author:** ![rEnDfOLi](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rEnDfOLi](https://community.homey.app/u/rEnDfOLi)\
**Post date:** [April 16, 2023, 9:40pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/24 "2023-04-16T21:40:31Z")

</div>

This might help you in your endeavor - I’ve had good experience with the a script I found some time ago: [https://homey.solweb.no/battery/battery](https://homey.solweb.no/battery/battery) (not mine).

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [July 7, 2023, 12:58pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/25 "2023-07-07T12:58:22Z")

</div>

Updated script I posted above - added counter of non responding devices - eg, in case you would like to initiate some action based on number of not-responding devices - please note this is the version I’m using, so feel free to change relevant variables below the section _// Filter devices to check_

**Changelog :**  
0.1 - update - converting notReportingCount to a number - if you used previous version of script, delete tag by await tag(‘notReportingCount’, null);\*  
0.2 - added filtering based on device app type - thanks @Peter_Kawa\*  
0.3 - update for new HomeyScript - **compatible now only with HomeyScript v. 3.5.1 and later**  
0.3b - fixed for THEN card (returning TEXT value), primary use-better use is for AND card though  
0.4 - added option to exclude ZONEs  
0.5 - better output formatting and fixes date times sometimes N/A  
0.6 - added ability to exclude ZWave/Zigbee devices or all others  
0.7 - Adds battery-level monitoring for ANY devices  
0.8 — Any-device LastUpdated + Battery monitor, NA/invalid lastUpdated ⇒ NOK with reason codes (“no updates”), Uses system/runtime time zone by default (universal); optional TIME\_ZONE override

> <https://github.com/shaarkys/Homey_Scripts/blob/main/checkLastUpdate_any.js>

 ![example](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/d/2db49d27eddd55c335881b891229a18323c344cc.png)

Zigbee ONLY version : [A script to check sensor last update - #39 by Sharkys](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/39)

---

<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:** [July 7, 2023, 1:47pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/26 "2023-07-07T13:47:28Z")

</div>

> [@Sharkys](#):
>
> `tag('notReportingCount', notReportingCount.toString())`

I used this in HS to force a value to be considered numeric, not sure if it works inside the tag arguments

```auto
tag('notReportingCount', Number(notReportingCount)())

```

---

<div class="post-metadata">

**Author:** ![Timmm](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/timmm/32/110251_2.png) [@Timmm](https://community.homey.app/u/Timmm)\
**Post date:** [September 8, 2023, 10:13pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/27 "2023-09-08T22:13:23Z")

</div>

Hi, how do you mean and do this?  
Can I use it to pull more updates out of a sensor?  
I have the aware humidity and temp sensor. It doesn’t update a lot. And am triggering my shower ventilator with this moist measurement. If it takes too long, it doesn’t work correctly.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [September 12, 2023, 12:49pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/28 "2023-09-12T12:49:44Z")

</div>

> [@Timmm](#):
>
> Can I use it to pull more updates out of a sensor?

No, but you can use it to check when a value has been updated and how long ago that was.

---

<div class="post-metadata">

**Author:** ![Cuprum](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/cuprum/32/41409_2.png) [@Cuprum](https://community.homey.app/u/Cuprum)\
**Post date:** [September 16, 2023, 12:21am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/29 "2023-09-16T00:21:56Z")

</div>

Sorry, in general You can NOT pull more updates from sensor - most radio protocols on bat-powered devices save power and switch radio off. That means, the device is not listening radio traffic unless “wake up periods” or if there is something important to say ( for example: “Hi! i detected water here!” )  
Yes, of course You can play with reporting intervals and also with threshholds on sensor - but this may reduce baterry life ( if bat. powered device ).

From my personal experience - also attempted first to check room moisture. Nice to have, but to slow and data to disperced ( for my case there is difference in moisture during summer and winter - but not only ) So… i just bougth a water leakage sensor and put it under the shower. Not disturbing at all - a small box hanging directly on wall under the shower head, around 5 centimeters abowe the floor. NB! there may be smart to put behind little bit more 2-sided tape, because there may be water staying between wall and sensor ( which one holds alarm on). And actually i use also timer in central box - the water alarm switch vent on & starts 1.5h timer. If timer reaches back to zero, then vent is switched off.  
Ok, there are more whistles also… “hardware” switch on also sets countdown… etc.

---

<div class="post-metadata">

**Author:** ![Tirrazo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tirrazo/32/55444_2.png) [@Tirrazo](https://community.homey.app/u/Tirrazo)\
**Post date:** [September 18, 2023, 8:36am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/30 "2023-09-18T08:36:32Z")

</div>

I ran your script and got this:  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/0/600c7dd76f71fa477bb397dc2fa16aefc42c99ad.png)

Is this checking all the zigbee devices, doesn’t matter what type it is?

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [September 18, 2023, 8:40am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/31 "2023-09-18T08:40:10Z")

</div>

> [@Tirrazo](#):
>
> doesn’t matter what type

It matters, you need to adjust conditions in the script… name and-or class (device type)

> [@Sharkys](#):
>
> ```auto
> if (!device.name.match(/temperature/i)) continue; // Include by regex device name
> if (device.name.match(/Flood|TVOC|Netatmo Rain|Motion|Flora|Rear gate Vibration Sensor|Vibration Sensor Attic Doors/i)) continue; // Exclude devices with given name
> if (!device.class.match(/sensor|button|remote|socket|lights/i)) continue; // Include device types
> 
> ```

---

<div class="post-metadata">

**Author:** ![Tirrazo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tirrazo/32/55444_2.png) [@Tirrazo](https://community.homey.app/u/Tirrazo)\
**Post date:** [September 18, 2023, 5:45pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/32 "2023-09-18T17:45:44Z")

</div>

Ok. That will be quite a job 😃

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [September 18, 2023, 5:56pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/33 "2023-09-18T17:56:54Z")

</div>

Or simply comment out the first two IF, it will give you everything from the class

---

<div class="post-metadata">

**Author:** ![Tirrazo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tirrazo/32/55444_2.png) [@Tirrazo](https://community.homey.app/u/Tirrazo)\
**Post date:** [September 18, 2023, 9:07pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/34 "2023-09-18T21:07:00Z")

</div>

Comment out, you mean just dont write anything there?

---

<div class="post-metadata">

**Author:** ![Tirrazo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tirrazo/32/55444_2.png) [@Tirrazo](https://community.homey.app/u/Tirrazo)\
**Post date:** [September 19, 2023, 10:15am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/35 "2023-09-19T10:15:49Z")

</div>

Can you give an example. I am pretty rooky on this scripting 😵

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [September 19, 2023, 10:40am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/36 "2023-09-19T10:40:37Z")

</div>

Simply take the script above and launch it - based on the output, adjust it as needed.

Eg. without modifying anything, this will give you state of temperature sensors only, which were not updated in last 0.8 hours.

> [@A script to check sensor last update](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/25):
>
> Updated script I posted above - added counter of non responding devices - eg, in case you would like to initiate some action based on number of not-responding devices - please note this is the version I’m using, so feel free to change relevant variables below the section // Filter devices to check Changelog : 0.1 - update - converting notReportingCount to a number - if you used previous version of script, delete tag by await tag(‘notReportingCount’, null);\* 0.2 - added filtering based on dev…

By launching it from Adv. flow, you will also get Console output.  
 ![obrazek](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/0/a0e3788c405a38e55099b10a7d5873a249f390a1.png)

Or if you put // in front of this :

```auto
 if (!device.name.match(/temperature/i)) continue; //

```

You will get all sensor|button|remote|socket|lights …

---

<div class="post-metadata">

**Author:** ![Tirrazo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tirrazo/32/55444_2.png) [@Tirrazo](https://community.homey.app/u/Tirrazo)\
**Post date:** [September 19, 2023, 5:20pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/37 "2023-09-19T17:20:42Z")

</div>

Now something happened here, very good 🙂

Thank you!

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/9/79bfa7f3b9965a5436223035e4faa13c25f1312c.png)

I have to ask, there is a lot of devices that appear that is actually not a sensor. But the device class, who defines that?

App tiles I have made from the app “Net Scan” appears as sensors.  
Weather forecast app tiles are appearing as a sensor.

---

<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:** [September 19, 2023, 11:36pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/38 "2023-09-19T23:36:16Z")

</div>

> [@Tirrazo](#):
>
> But the device class, who defines that?

The developer, or the nature of device?

.  
Many capabilities are sensors. NetScan f.i. uses the sensor alarm capability.

> ![Screenshot_20230920-005443_Chrome](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/6/b6f035df800fbaa61e78515445aa77271a3c248a.jpeg)  
> Sensors example  
> ![Screenshot_20230920-010901_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/d/1d1411f247e961a170759e61a243cb82d2853ef5.jpeg)

.

For the [lines with the filters](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/31), I use these for example. Maybe it makes a bit more sense to you.

```auto
// Exclude Virtual Devices and apps:
if (device.driverUri.match('vdevice|nl.qluster-it.DeviceCapabilities|nl.fellownet.chronograph|net.i-dev.betterlogic|com.swttt.devicegroups|com.gruijter.callmebot|com.netscan' )) continue; 

// Exclude by (parts of) device name
if (device.name.match('^se|^pr|TST|z_|z |z. |IR|Arri|Rebo|rada|KNM|Timeline')) continue; 

```

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [September 20, 2023, 6:53am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/39 "2023-09-20T06:53:16Z")

</div>

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 😉

**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.5** - added option to exclude ZONES, moved variables to the top to be more user friendly  
**Version 0.6** - improved formatting of the output  
**Version 0.7** - fixes  
**Version 0.8** - battery level added

> <https://github.com/shaarkys/Homey_Scripts/blob/main/checkLastUpdate_Zigbee.js>

Example for 2 hours threshold :

 ![inclbatter](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/5/e5051e48773bb0566007c54428e0b85aad111bd3.png)  
 ![nokstatbatt](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/d/cd59fa2ff16618579523992e77a66efcdda83528.png)

All device types version : [A script to check sensor last update - #25 by Sharkys](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/25)

---

<div class="post-metadata">

**Author:** ![Felho](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/felho/32/38916_2.png) [@Felho](https://community.homey.app/u/Felho)\
**Post date:** [October 2, 2023, 7:23pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/40 "2023-10-02T19:23:02Z")

</div>

> [@Sharkys](#):
>
> ```auto
> // Version 0.2
> // Script checks LastSeen property of Zigbee device
> // Using 2 hours default threshold
> // Thanks Caseda for [Homey Pro] overview script, which this was originally inspired by
> // Thanks to ChatGPT for consultations ;-)
> 
> const NotReportingThreshold = 2; // 2 hours
> const thresholdInMillis = NotReportingThreshold * 3600000; // convert hours to milliseconds
> 
> let ZigbeeDevicesLastSeen = [];
> let notReportingCount = 0;
> let DevicesNotReporting = [];
> 
> // Function to format a date as "dd-mm-yyyy, hh:mm:ss"
> function formatDate(date) {
> const day = date.getDate().toString().padStart(2, '0');
> const month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are 0-indexed
> const year = date.getFullYear().toString();
> const hours = date.getHours().toString().padStart(2, '0');
> const minutes = date.getMinutes().toString().padStart(2, '0');
> const seconds = date.getSeconds().toString().padStart(2, '0');
> 
> return `${day}-${month}-${year}, ${hours}:${minutes}:${seconds}`;
> }
> 
> // Function to check last seen state of Zigbee devices
> async function checkZigbeeLastSeen() {
> try {
> const result = await Homey.zigBee.getState();
> 
> const okDevices = [];
> const nokDevices = [];
> const routerDevices = [];
> const endDevices = [];
> 
> for (const device of Object.values(result.nodes)) {
> // Filter devices to check
> if (device.class && !device.class.match(/sensor|button|remote|socket|lights/i)) continue; // Include device types
> //if (!device.name.match(/temperature/i)) continue; // Include by regex device name
> if (device.name.match(/dimmer|light|bulb|spot/i)) continue; // Exclude by regex device name
> // Include last seen information
> const lastSeenDate = new Date(device.lastSeen);
> const lastSeenFormatted = formatDate(lastSeenDate);
> 
> // Check against NotReportingThreshold
> const currentTime = Date.now();
> const timeSinceLastSeen = currentTime - lastSeenDate.getTime();
> 
> if (timeSinceLastSeen >= thresholdInMillis) {
> deviceName = device.name + ' ' + lastSeenFormatted + ' (' + device.type.toLowerCase() + ') (NOK)';
> nokDevices.push(deviceName);
> notReportingCount++; // Increment the count of not reporting devices
> DevicesNotReporting.push(deviceName); // Add the device to the list of not reporting devices
> } else {
> deviceName = device.name + ' ' + lastSeenFormatted + ' (' + device.type.toLowerCase() + ') (OK)';
> okDevices.push(deviceName);
> }
> 
> if (device.type.toLowerCase() === 'router') routerDevices.push(deviceName);
> if (device.type.toLowerCase() === 'enddevice') endDevices.push(deviceName);
> }
> 
> // Log Zigbee devices and their types
> console.log(okDevices.length, 'OK Zigbee devices', '(' + routerDevices.length + ' Router, ' + endDevices.length + ' End device)');
> console.log(nokDevices.length, 'NOK Zigbee devices');
> console.log('---------------------------------------------');
> console.log('OK ZigBee device(s):');
> console.log(okDevices.join('\r\n'));
> console.log('---------------------------------------------');
> console.log('NOK ZigBee device(s):');
> console.log(nokDevices.join('\r\n'));
> console.log('---------------------------------------------');
> 
> // Output for script AND card
> await tag('InvalidatedDevices', DevicesNotReporting.join('\n'));
> await tag('notReportingCount', notReportingCount);
> 
> // Return both values
> return {
> notReportingCount: notReportingCount,
> DevicesNotReporting: DevicesNotReporting
> };
> } catch (error) {
> console.error('Failed: Getting ZigBee state', error);
> // Output for script AND card
> await tag('InvalidatedDevices', '');
> await tag('notReportingCount', -1); // Set to -1 to indicate an error
> 
> // Return both values
> return {
> notReportingCount: -1,
> DevicesNotReporting: [],
> };
> }
> }
> 
> // Execute the Zigbee check function
> checkZigbeeLastSeen()
> .then((result) => {
> // You can access result.notReportingCount and result.DevicesNotReporting here
> console.log('Not Reporting Count:', result.notReportingCount);
> console.log('Devices Not Reporting:', result.DevicesNotReporting);
> })
> .catch((error) => {
> console.error('Error:', error);
> });
> 
> // Explicitly return true
> return true;
> 
> ```

how can write this script the timeline or telegram notification?

[Previous page](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142.md?page=1)

[Next page](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142.md?page=3)
