# 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:** 4

<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:** [May 19, 2024, 1:56pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/63 "2024-05-19T13:56:43Z")

</div>

Ah, so it’s a `tag` create/update error?  
Hmmmm, what’s changed?  
Can’t find anything here:

> **[Tutorial: Migrating deprecated scripts - HomeyScript](https://athombv.github.io/com.athom.homeyscript/tutorial-migrate.html)**

---

<div class="post-metadata">

**Author:** ![Derf\_Brother](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/derf_brother/32/19097_2.png) [@Derf\_Brother](https://community.homey.app/u/Derf_Brother)\
**Post date:** [May 19, 2024, 2:59pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/64 "2024-05-19T14:59:03Z")

</div>

thnx, got a good tip from Peter\_Kawa

---

<div class="post-metadata">

**Author:** ![Derf\_Brother](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/derf_brother/32/19097_2.png) [@Derf\_Brother](https://community.homey.app/u/Derf_Brother)\
**Post date:** [May 19, 2024, 3:00pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/65 "2024-05-19T15:00:25Z")

</div>

thnx, this works. I also see some follow up on the THEN. Hope something good comes from this

---

<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:** [May 19, 2024, 4:45pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/66 "2024-05-19T16:45:31Z")

</div>

Not really, the problem is/was my misunderstanding of tag function - it do not return anything as Athom dev. said : “tag has no return value” - [com.athom.homeyscript/app.js at 09d6d7397f7dcd6c001650aa7a1d3834d57734b6 · athombv/com.athom.homeyscript · GitHub](https://github.com/athombv/com.athom.homeyscript/blob/09d6d7397f7dcd6c001650aa7a1d3834d57734b6/app.js#L327)

---

<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:** [May 19, 2024, 4:54pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/67 "2024-05-19T16:54:42Z")

</div>

**Both scripts updated**

0.3b - fixed for THEN card (returning TEXT value), primary use-better use is for AND card though with variables/tag InvalidatedDevices / notReportingCount

**General version**

> [@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…

**Zigbee version**

> [@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.3b // Script checks LastSeen property of Zigbee device // Using 2 hours default threshold // Thanks Caseda for […

---

<div class="post-metadata">

**Author:** ![Derf\_Brother](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/derf_brother/32/19097_2.png) [@Derf\_Brother](https://community.homey.app/u/Derf_Brother)\
**Post date:** [May 19, 2024, 6:04pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/68 "2024-05-19T18:04:26Z")

</div>

thnx. Zigbee 0.3b is working fine. Did not check the general 03.b

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [May 25, 2024, 12:14pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/69 "2024-05-25T12:14:42Z")

</div>

I love this script… 😉

But I as well have the problem that some routers (powered devices) do not update their “last seen” when not used for a while. In my case only Ikea bulbs and sockets as well.  
I would like to use the script mostly to report battery powered devices not reporting anymore because of a low battery (or failure of course).

Is it an option to include a/some line(s) in the script to exclude router devices, @Sharkys?  
Or filter on router/end device?  
I tried my best, but couldn’t find it… ☹

---

<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:** [May 25, 2024, 6:49pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/70 "2024-05-25T18:49:37Z")

</div>

> [@Henk\_Renting](#):
>
> Is it an option to include a/some line(s) in the script to exclude router devices,

Added into version 0.4 🙂

> [@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…

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [May 25, 2024, 8:34pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/71 "2024-05-25T20:34:54Z")

</div>

Did I already mention you are the best?  
And the quickest… 😉

Thanks @Sharkys!

---

<div class="post-metadata">

**Author:** ![DaDa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dada/32/79161_2.png) [@DaDa](https://community.homey.app/u/DaDa)\
**Post date:** [June 26, 2024, 2:43pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/72 "2024-06-26T14:43:01Z")

</div>

I’m getting a

```auto
Failed: Getting ZigBee state TypeError: Cannot read properties of undefined (reading 'getState')
    at checkZigbeeLastSeen (Test.js:32:39)
    at Test.js:106:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

———————————————————
✅ Script Success
↩️ Returned: "Error in retrieving ZigBee state"

```

and :32 reads  
` const result = await Homey.zigbee.getState();`

Running a fully updated HP23. Did I miss something?

---

<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:** [June 27, 2024, 12:02am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/73 "2024-06-27T00:02:38Z")

</div>

This works @ Pro 2019, can you test it?

```auto
const result = await Homey.zigbee.getState();
log(result);

```

---

<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:** [June 27, 2024, 6:23am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/74 "2024-06-27T06:23:47Z")

</div>

> [@DaDa](#):
>
> Did I miss something?

![yellow](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/9/29c2c18712aaed8a008de88558cdf645738b14f9.png)

If you have this Yellow flag, you must recreate the script as you are still using old version of HomeyScript.  
Read more on [Tutorial: Migrating deprecated scripts - HomeyScript](https://athombv.github.io/com.athom.homeyscript/tutorial-migrate)

**Long story short** - create new script and copy paste the script from the previous version.

---

<div class="post-metadata">

**Author:** ![Sjoerd1](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sjoerd1/32/33892_2.png) [@Sjoerd1](https://community.homey.app/u/Sjoerd1)\
**Post date:** [July 21, 2024, 10:27am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/75 "2024-07-21T10:27:04Z")

</div>

’m making a mistake somewhere. I’m using version 0.4 but for all devices, I get: NaN-NaN-NaN, NaN:NaN:NaN. Invalid value for time?

Am I doing something wrong…? Additionally, the script now indicates that all sensors are OK. But there’s one sensor that hasn’t responded for 3 days. (that’s why I want to use this script)

 ![Scherm­afbeelding 2024-07-21 om 12.23.51](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/8/e86fe44d79e04cbe22ed720c68a633bb5b7ab6ab.png)

---

<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 21, 2024, 11:29am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/77 "2024-07-21T11:29:54Z")

</div>

Did you just copy paste the script and run it and with log scrolled up, share the screen, eg:

![alldevices](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/6/269e936f0bbe5064c5e0e7bc3aa47463b8d04ff7.png)

or

![zigbee](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/0/c06acfe50d337f1ba3f2c0cce3c436f2a1a8ee79.png)

---

<div class="post-metadata">

**Author:** ![Sjoerd1](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sjoerd1/32/33892_2.png) [@Sjoerd1](https://community.homey.app/u/Sjoerd1)\
**Post date:** [July 21, 2024, 6:11pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/78 "2024-07-21T18:11:56Z")

</div>

Thanks for taking a look. I copied the script exactly as is. I only changed the ReportingThreshold to 24. But even without that change, I’m still getting NaN-NaN-NaN.

 ![Scherm­afbeelding 2024-07-21 om 20.07.54](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/d/bddc72f314cf28c75e4d71050b02919e43fd0070.png)  
 ![Scherm­afbeelding 2024-07-21 om 20.09.07](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/1/41cb075e65bc849fc8c5fd1a1ce36cb5f9ac45fb.png)  
 ![Scherm­afbeelding 2024-07-21 om 20.13.44](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/f/cfe6870fe1e0b8e7974f80821f65565edbd41839.png)

---

<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 21, 2024, 8:54pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/79 "2024-07-21T20:54:04Z")

</div>

Hm, interesting, Which Homey firmware version and HomeyScript you are on ?

Can you also go to [Homey Developer Tools](https://tools.developer.homey.app/tools/api-playground) and launch :

> Homey.Zigbee.getState();

And then copy here part like this one :  
 ![dev](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/c/fcbb0ccad8fee7e640cf618779402421c4a3ae2c.png)  
_(if you want, obfuscate ieeeAddr)_

---

<div class="post-metadata">

**Author:** ![Sjoerd1](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sjoerd1/32/33892_2.png) [@Sjoerd1](https://community.homey.app/u/Sjoerd1)\
**Post date:** [July 22, 2024, 12:53pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/80 "2024-07-22T12:53:47Z")

</div>

Homeyscript 3.5.1 and Homey is now on 11.0.0. Updated this morning, was on 10.0.10. (Homey Pro 2019).

I get this error with the launch of ‘Homey.Zigbee.getState();’

 ![Scherm­afbeelding 2024-07-22 om 14.51.11](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/4/24390b53d53a3ca79ecce80c25d0bdaeb591df03.png)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 22, 2024, 12:55pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/81 "2024-07-22T12:55:03Z")

</div>

Should be `Homey.zigbee.getState()` (lower case ‘z’)

---

<div class="post-metadata">

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

</div>

Ah! That worked indeed.

I don’t see any “lastSeen” like in your screenshot…

 ![Scherm­afbeelding 2024-07-22 om 14.56.07](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/b/2b3c71ed4124a9b73911e859de2d79ce46e8a60d.png)

---

<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 22, 2024, 1:41pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/83 "2024-07-22T13:41:39Z")

</div>

> [@robertklep](#):
>
> Should be `Homey.zigbee.getState()` (lower case ‘z’)

Damn autocorrect, although it shouldn’t touch code blocks 🥴

> ![Screenshot_20240722-152505_Slack](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/2/a2823d08b8123638a1d0b947d02bd63203cac375.jpeg)

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

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