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

<div class="post-metadata">

**Author:** ![PeterHa](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@PeterHa](https://community.homey.app/u/PeterHa)\
**Post date:** [January 19, 2025, 11:28am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/105 "2025-01-19T11:28:35Z")

</div>

Yes, I meant Zigbee, sorry.  
Thanks @Sharkys for the update, it’s now perfect for me! This helps now to avoid a open window in the basement for 3 days ´, because temperature sensor was not longer responding as happend 2 weeks ago. 🙂

Just another question regarding the version of all devices (not only zigbee)…  
Is it possible to exclude the zigbee devices from the output, because zigbee works more accurate in a separate script?  
I looked into the code, but I didn’t found any obvious code to exclude zigbee (I’m not a dev).

---

<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:** [January 19, 2025, 2:07pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/106 "2025-01-19T14:07:56Z")

</div>

> [@PeterHa](#):
>
> because temperature sensor was not longer responding as happend 2 weeks ago

While I use that script myself, for such events might be also useful to check TRENDs eg. based on app [Insight Trends Reloaded App for Homey | Homey](https://homey.app/en-us/app/com.spkes.insightTrendsReloaded/Insight-Trends-Reloaded/) (no updates = trend is 0)

> [@PeterHa](#):
>
> Is it possible to exclude the zigbee devices from the output

Hm, I didn’t know it’s still Christmas. 🙃 … check out next version 0.6.

---

<div class="post-metadata">

**Author:** ![vletroye](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/vletroye/32/101044_2.png) [@vletroye](https://community.homey.app/u/vletroye)\
**Post date:** [January 19, 2025, 8:26pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/107 "2025-01-19T20:26:48Z")

</div>

Hello… I am a bit confused with the outcome of the scripts… Maybe I didn’t get what “last update” is. I read this thread and understood that it’s the same as “Last Seen”. Correct ?

I did “Interview” a Philips Hue Dimmer (named “Dimmer Guest” here under) and one can see that the “Last Seen” value is “2 minutes ago”.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/b/fb152dfaba50e038e45eff0d159486a4d9f61b13.png)

But when I run the script (latest version 0.6), it reports : Dimmer guest (18-02-2024, 11:30:24 - remote) (NOK)

I did the same test with an “Aqara Cube” , that you can turn of shake to trigger actions, and that I didn’t touch for a while… The script was initially reporting: Cube (15-01-2025, 19:43:11 - sensor) (NOK). But once I did “Rotate” it, the script didn’t report it anymore. So, no “general problem”…

I have the same “issue” with all (12) my other Philips Hue Dimmers. And looking via the Developer Tool the details of the Dimmers, I realize that the “last update” reported by the script could actually be the “last changed” date of the battery alarm ?

Is is possible ?

* * *

**Some Dimmers with last battery alarm = 11 months**

Dimmer guest (18-02-2024, 11:30:24 - remote) (NOK)

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/7/57fd8af4e8fc941eee0a29a426308929b1045788.png)

Dimmer bureau (15-02-2024, 16:39:05 - remote) (NOK)

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/a/6a727f4af5ac41c1b7d38263d1712b68ecd37094.png)

* * *

**Some Dimmers with last battery alarm = 8 months**

Dimmer Klara (19-05-2024, 09:08:32 - remote) (NOK)

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/f/8f92a2e96d24a17b78db783c0f46e19ddbb66f7e.png)

Dimmer 1 (19-05-2024, 11:07:26 - remote) (NOK)  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/2/b2ff4ec4090c952c200ef2f7bde22ed86cbca084.png)

PS: I realize I have a similar behaviour with “homey:app:com. **netscan** :ip\_driver” devices… The “Last Update” date is the last “Alarm” (“Offline Alarm” for NetScan devices)

Camera Living (23-07-2024, 23:42:51 - sensor) (NOK)

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/3/538bc0379a86aa6e283b7d1536d3a42843d63ce0.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:** [January 19, 2025, 8:55pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/108 "2025-01-19T20:55:14Z")

</div>

> [@vletroye](#):
>
> Hello… I am a bit confused with the outcome of the scripts… Maybe I didn’t get what “last update” is. I read this thread and understood that it’s the same as “Last Seen”. Correct ?

For Zigbee version of the script, yes, it is. I checked mine and it matches. Dimmers are in general in my case even not responding for 24 hours - that’s why I’m checking temperature sensors eg. on 1 hour value compared to eg. dimmer, which I check basically for values not updated \>2 days etc.

For “any devices” version it takes the latest capability update available. In case of Zigbee devices Last seen is more accurate then.

---

<div class="post-metadata">

**Author:** ![vletroye](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/vletroye/32/101044_2.png) [@vletroye](https://community.homey.app/u/vletroye)\
**Post date:** [January 19, 2025, 9:13pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/109 "2025-01-19T21:13:35Z")

</div>

Thx !

I see your code doing that indeed:

```auto
  // Gather the latest lastUpdated
  if (device.capabilitiesObj) {
    for (const capability of Object.values(device.capabilitiesObj)) {
      if (!capability.lastUpdated) continue;
      const capTime = new Date(capability.lastUpdated).getTime();
      if (!maxLastUpdatedTime || capTime > maxLastUpdatedTime) {
        maxLastUpdatedTime = capTime;
      }
    }
  }

```

So, on my side I will exclude the devices for which that “latest capability update” does not reflect the actual “last communication” (My Dimmers, My Network devices, My Z-Wave devices, …).

It’s a pity too that Homey did expose a true “Last Seen” property… For Z-wave devices, I have the same “issue” with sockets that have not been switch on/off since a while, but that are well (as nodes) still available and responding in the Z-wave Network…

For the community App, like the “Network devices” (com.netscan), the App should themselves be able to update such a “last seen” property when it checks (ex.: ping) the device…

Not that easy to really detect devices that are “lost” 😕

---

<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:** [January 19, 2025, 9:28pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/110 "2025-01-19T21:28:51Z")

</div>

> [@vletroye](#):
>
> For Z-wave devices, I have the same “issue” with sockets that have not been switch on/off since a while

Sometimes for ZWAVE you can setup wakeup intervals and reporting thresholds to mitigate this, or simply set long enough interval to prevent false positives.

> [@vletroye](#):
>
> community App, like the “Network devices” (com.netscan)

Well, this app itself update the device online in case of device status change, so again this works as designed, unless developer would rewrite it (which I don’t think is required for such case, that’s why it’s by default excluded in the example). Also eg. for Wifi connected devices, developer can set device unavailability state and you can set trigger based on it - true is it’s also not working always for some unknown reason, so I’m using error catching - eg. do something with eg. thermostat and in case of error, report that there was an error.

> [@vletroye](#):
>
> detect devices that are “lost”

Based on my experience, the most problematic ones are anyway Zigbee, ZWAVE (sometimes, eg. dying FGR223) and naturally Bluetooth on HP23 (never works).

---

<div class="post-metadata">

**Author:** ![PeterHa](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@PeterHa](https://community.homey.app/u/PeterHa)\
**Post date:** [January 28, 2025, 11:57pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/111 "2025-01-28T23:57:47Z")

</div>

Hi Sharkys,  
I found now some time to configure the scripts for zigbee and all.  
Zigbee script is now working perfect with a 12 hour update.  
In the all devices script I excluded zigbee and 24 hour update. But I’m not really happy with that because a lot of devices must be excluded because last update is \> 24 hours.

Thanks for the hint to Insight Trends Reloaded App, I’ll have a look to that.

I sent some coins for beer, coffee or valium to answer more questions. 🍺 ☕ Thanks for your support

---

<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:** [January 29, 2025, 5:51am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/112 "2025-01-29T05:51:49Z")

</div>

Hi @PeterHa , thank you for donation, appreciated and congratulation to be first time ever 😉

As for updates, this is exactly the reason why you can set specific inclusion/exclusion but in general, I keep lower time period for sensors like temperature, light sensors (eg. 1 hour) and longer like remote controls (excluded or some \>24 hours), lights (24 hours) etc. Some of them I even check only weekly. It’s really specific to each device type, brand and even frequency of the use (eg. I check motion sensors only when I’m at home).

---

<div class="post-metadata">

**Author:** ![Anthony\_Clarke](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/anthony_clarke/32/101325_2.png) [@Anthony\_Clarke](https://community.homey.app/u/Anthony_Clarke)\
**Post date:** [May 18, 2025, 3:45am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/113 "2025-05-18T03:45:11Z")

</div>

Perfect! Nearly all I was looking for, would it be able to report Battery level for each device too?

---

<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 18, 2025, 5:22am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/114 "2025-05-18T05:22:26Z")

</div>

Check out **version 0.8**

> [@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.5 - added option to exclude ZONES, moved varia…

---

<div class="post-metadata">

**Author:** ![Anthony\_Clarke](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/anthony_clarke/32/101325_2.png) [@Anthony\_Clarke](https://community.homey.app/u/Anthony_Clarke)\
**Post date:** [May 18, 2025, 5:53am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/115 "2025-05-18T05:53:50Z")

</div>

Amazing! Thanks…

Here is my output (partial), my IKEA Motion Sensors are not reporting Battery level, does that sound right?

```auto
OK Zigbee device(s): 12
# Device Name Last Seen Type Batt Status
------------------------------------------------------------------------------------
1 BackRoof SNZB-02P 18-05-2025, 05:52:08 enddevice 60% (OK)  
2 TV-ArtRoom - SNZB-02D 18-05-2025, 05:52:06 enddevice 100% (OK)  
3 Office Motion Sensor 18-05-2025, 04:37:05 enddevice N/A (OK)

```

---

<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 18, 2025, 6:02am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/116 "2025-05-18T06:02:00Z")

</div>

Did you check directly in your Homey for given device ?

---

<div class="post-metadata">

**Author:** ![Anthony\_Clarke](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/anthony_clarke/32/101325_2.png) [@Anthony\_Clarke](https://community.homey.app/u/Anthony_Clarke)\
**Post date:** [May 18, 2025, 7:22am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/117 "2025-05-18T07:22:05Z")

</div>

![CleanShot 2025-05-18 at 17.19.36@2x](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/8/b8dee8d6241daf3b330fec13a9b57cc4d45d9ae2.jpeg)  
I’ll look into tomorrow, it’s working ok, as is the front door sensor that doesn’t show any battery level.  
 ![CleanShot 2025-05-18 at 17.21.31@2x](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/9/5920c674aebed761abdfc5bc12fdb51c23ad21fb.jpeg)

---

<div class="post-metadata">

**Author:** ![Anthony\_Clarke](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/anthony_clarke/32/101325_2.png) [@Anthony\_Clarke](https://community.homey.app/u/Anthony_Clarke)\
**Post date:** [July 12, 2025, 11:50pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/118 "2025-07-12T23:50:56Z")

</div>

Come back to this after some personal distractions, and same after running script 0.8. Checked Homey Device Status on the Front Door and Office Motion Sensor, both are IKEA TRADFRI motion sensor running firmware 2.0.022. Looking at Battery Status in Device Settings both show the same image of Battery ?. Any thoughts @Sharkys (Many thanks)

 ![CleanShot 2025-07-13 at 09.49.50@2x](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/6/9687b6028e9601f7b9e9a2dd1a6bb3bdfc8b1309.jpeg)

```OK
# Device Name Last Seen Type Batt Status
------------------------------------------------------------------------------------
1 BackRoof 12-07-2025, 23:46:01 enddevice 100% (OK)  
2 TV-ArtRoom - SNZB-02D 12-07-2025, 23:45:26 enddevice 100% (OK)  
3 Back Living Room SNZB-02 12-07-2025, 23:45:51 router 100% (OK)  
4 Office Motion Sensor 12-07-2025, 23:39:16 enddevice N/A (OK)  
5 Motion Sensor 12-07-2025, 23:43:09 enddevice 100% (OK)  
6 Xiaomi Light Sensor 12-07-2025, 23:34:03 enddevice 100% (OK)  
7 Front Door 12-07-2025, 23:46:04 enddevice N/A (OK)  
8 BackDeck 12-07-2025, 23:46:01 enddevice 90% (OK)  
9 Ella Bedroom 12-07-2025, 23:45:58 enddevice 17% (OK)  
10 Front Roof 12-07-2025, 23:45:42 enddevice 100% (OK)  
11 Kitchen 12-07-2025, 23:45:53 enddevice 100% (OK)  
12 Side Deck 12-07-2025, 23:45:49 enddevice 100% (OK)  
13 Sam's Room 12-07-2025, 23:45:55 enddevice 100% (OK)  

NOK Zigbee device(s): 1
# Device Name Last Seen Type Batt Status
------------------------------------------------------------------------------------
1 Upstairs Living SNZB-02D 12-07-2025, 19:56:59 enddevice 100% (NOK) 

Low-battery device(s) (≤30%): 1
1. Ella Bedroom 17%
---------------------------------------------

———————————————————
✅ Script Success
↩️ Returned: "Not Reporting Count: 1\nLow Battery Count: 1\nDevices Not Reporting:\nUpstairs Living SNZB-02D 12-07-2025, 19:56:59 (enddevice)\nDevices Low Battery:\nElla Bedroom 17%"
type or paste code here

```

---

<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 13, 2025, 4:25am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/119 "2025-07-13T04:25:27Z")

</div>

Some IKEA devices don’t report battery state, check the device settings

---

<div class="post-metadata">

**Author:** ![Bert\_Wissink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bert_wissink/32/30075_2.png) [@Bert\_Wissink](https://community.homey.app/u/Bert_Wissink)\
**Post date:** [July 28, 2025, 7:11pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/120 "2025-07-28T19:11:06Z")

</div>

A very nice and helpful script working for Zigbee devices.  
I’m just struggling to include Z-Wave devices in this script (I have 2 Fibaro thermostat knobs). Any hint? Especially for the battery level.

---

<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 28, 2025, 7:27pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/121 "2025-07-28T19:27:42Z")

</div>

Not sure if I follow, which script version are you using ? The battery level is available in the Zigbee version only and it can’t be used for ZWave devices. You can use the general one but without battery level reported.

---

<div class="post-metadata">

**Author:** ![Bert\_Wissink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bert_wissink/32/30075_2.png) [@Bert\_Wissink](https://community.homey.app/u/Bert_Wissink)\
**Post date:** [July 28, 2025, 7:43pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/122 "2025-07-28T19:43:08Z")

</div>

I am using your Zigbee version script

For my Fibaro devices I’m using the homey:app:com.fibaro:FGT-001 driver from Athom. One of the available device capabilities is measure\_battery, see snippet below.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/2/928bed1f7bd7e159f4354ecd43dfa4a1316a953b.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 28, 2025, 7:46pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/123 "2025-07-28T19:46:30Z")

</div>

You are using Zigbee script for ZWave device. You shall use the general script, however it does not report battery level.

---

<div class="post-metadata">

**Author:** ![Bert\_Wissink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bert_wissink/32/30075_2.png) [@Bert\_Wissink](https://community.homey.app/u/Bert_Wissink)\
**Post date:** [July 28, 2025, 7:49pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/124 "2025-07-28T19:49:47Z")

</div>

Yeah, I know, but I wanted to build in ZWave devices with battery checks, but too complex for me. Tried a couple of things, but failed 🙃  
No worries though, thanks!

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

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