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

<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:** [October 2, 2023, 8:03pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/41 "2023-10-02T20:03:15Z")

</div>

Something like

```auto
Homey.flow.runFlowCardAction({
uri: 'homey:manager:notifications',
id: 'create_notification',
args: {
text: 'Test text sent by Timeline_message.js'
}
});

```

---

<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, 8:18pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/42 "2023-10-02T20:18:53Z")

</div>

> [@Peter\_Kawa](#):
>
> ```auto
> Homey.flow.runFlowCardAction({
> uri: 'homey:manager:notifications',
> id: 'create_notification',
> args: {
> text: 'Test text sent by Timeline_message.js'
> }
> });
> 
> ```

and how this rows can put the script end or how? Advanced flow not showing all information like when script test run?

---

<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:** [October 2, 2023, 8:23pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/43 "2023-10-02T20:23:39Z")

</div>

Why you would need that ? You can process output tags and to whatever you want in flows.

> InvalidatedDevices  
> notReportingCount

---

<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, 8:38pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/45 "2023-10-02T20:38:47Z")

</div>

because my aqara wireless wall switch battery status report not valid the app, and today is 2. wall switch is not working because the battery is low down and app say 100% status and I want to now if something devices is low battery  
But if you have any solution how make a flow I’m listening. Thanks

---

<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:** [October 3, 2023, 5:28am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/46 "2023-10-03T05:28:58Z")

</div>

> [@Felho](#):
>
> aqara wireless wall switch battery status report not valid the app

Zigbee ? If it’s Zigbee I would recommend to use [A script to check sensor last update - #39 by Sharkys](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/39) otherwise use [A script to check sensor last update - #25 by Sharkys](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/25)

The flow is quite trivial :

 ![obrazek](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/1/3138302a5e2d549183ffc8de5e41ce7463b17f76.png)

…add some trigger (time, condition based or any you want).  
_There is also check included in this example to ensure you will not get repeated notifications about the_ same devices.

---

<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 3, 2023, 6:03am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/48 "2023-10-03T06:03:42Z")

</div>

> [@Felho](#):
>
> thanks, no have any script that can read zigbee and device correct battery status, that is I like. thanks for your time help me.

thanks, no have any script that can read zigbee and device correct battery status, that is I like. thanks for your time help me.

---

<div class="post-metadata">

**Author:** ![kruza26](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/kruza26/32/36806_2.png) [@kruza26](https://community.homey.app/u/kruza26)\
**Post date:** [October 11, 2023, 4:54pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/49 "2023-10-11T16:54:30Z")

</div>

Great job, this is exactly what i was looking for.

---

<div class="post-metadata">

**Author:** ![Groetsels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/groetsels/32/11456_2.png) [@Groetsels](https://community.homey.app/u/Groetsels)\
**Post date:** [October 16, 2023, 3:31pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/50 "2023-10-16T15:31:36Z")

</div>

additional question:  
If a device is not updating this “lastseen” date itself, how do I automaticly PING this device. (with a script)  
Just about the same question like this.

> [@How to automatically ping devices and use the result](https://community.homey.app/t/how-to-automatically-ping-devices-and-use-the-result/88845/3):
>
> Yes, I can ping battery devices. Look at this: [image] Yes, there is a battery status. But this doesn’t help much if the device stops communicating because of an error. The problem here was multiple problem. The chip itself died and it drained the batteries empty after just 30 days.

 ![ikea-routers-ping](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/6/56e2a0d6f12fc03d69df601b78e7a4c9a7783311.jpeg)

---

<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:** [October 16, 2023, 4:32pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/51 "2023-10-16T16:32:25Z")

</div>

> [@Groetsels](#):
>
> how do I automaticly PING this device. (with a script)

You can’t.

---

<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:** [October 16, 2023, 4:48pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/52 "2023-10-16T16:48:14Z")

</div>

What’s wrong with the script, it finds anything which hasn’t show any signs of life for the last xx hrs

---

<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:** [October 16, 2023, 7:21pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/53 "2023-10-16T19:21:47Z")

</div>

> [@Groetsels](#):
>
> Just about the same question like this.

IKEA Repeaters do not correctly update Last seen value - no idea why but I guess it"s Homey Zigbee issue or some incompatiblity. My advice (and what I did as well), filter it out in the script or stop using IKEA.

---

<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:** [October 16, 2023, 7:53pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/54 "2023-10-16T19:53:49Z")

</div>

> [@Sharkys](#):
>
> IKEA Repeaters do not correctly update Last seen value

That makes no sense 🤔 A “last seen” value is something that Homey determines.

(  
Repeater: “Hey Homey, you last saw me yesterday!”  
Homey: “No I didn’t, I’m seeing you right now!”  
Repeater: “…”  
)

---

<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:** [October 16, 2023, 8:02pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/55 "2023-10-16T20:02:10Z")

</div>

Yep and still, it doesn’t work with IKEA, I have no idea why. Now I looked on my Ikea Tradfri power socket - last seen two weeks ago :-)) Also there is some problem with storing / restoring this Last seen values upon restart - for some devices it’s reset upon restart, again no idea why. Submitted to Athom 2 / 3 weeks ago.

---

<div class="post-metadata">

**Author:** ![Groetsels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/groetsels/32/11456_2.png) [@Groetsels](https://community.homey.app/u/Groetsels)\
**Post date:** [October 17, 2023, 12:38pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/56 "2023-10-17T12:38:22Z")

</div>

What command is send from the development page with the “PING” button?  
After that the ‘lastseen’ date/time has a new value.

---

<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:** [October 17, 2023, 12:47pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/57 "2023-10-17T12:47:40Z")

</div>

> [@Groetsels](#):
>
> What command is send from the development page with the “PING” button?

You can try for yourself (replace “AA:BB:CC” with the full IEEE address of a device you want to ping):

```auto
Homey.zigbee.runCommand({
  "opts": { "ieeeAddr":"AA:BB:CC" },
  command: 'PING'
});

```

This works from the Web API Playground, but not from HomeyScript, so it cannot be automated.

---

<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 13, 2024, 8:04am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/58 "2024-05-13T08:04:40Z")

</div>

Updated both scripts to be compatible with Homeyscript 3.5.1 and later (now default, when new Homeyscript is created)

**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.3 // 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 ;-…

**Those scripts are not compatible anymore with Homeyscript \<3.5.1 and older, which is called “Classic”**  
 ![classic](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/7/678655e17cc1501a1a0ce216b30e0b8de3f440e7.png)

---

<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 18, 2024, 8:02pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/59 "2024-05-18T20:02:53Z")

</div>

Hello Sharkey,  
trying to use the script as replacement to use Homey script 3.5.1 but get error: “Invalid token type: string. Expected: String”  
HomeyPro23 version 11.0.0  
Would you know why this occurs since the script seems to be in use by others?

---

<div class="post-metadata">

**Author:** ![Marius\_Stensrod](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marius_stensrod/32/56540_2.png) [@Marius\_Stensrod](https://community.homey.app/u/Marius_Stensrod)\
**Post date:** [May 18, 2024, 8:19pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/60 "2024-05-18T20:19:47Z")

</div>

I am using a modified version of @Sharkys script, but do not know why you are getting the error. As you are waiting for @Sharkys , maybe you can post the script so i can help you as good as i can?

---

<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 18, 2024, 11:50pm UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/61 "2024-05-18T23:50:44Z")

</div>

Hi Derf,

I got a similar error when using the THEN card ‘Run code and return text-tag’  
The script works fine though, only returning the output to the text-tag seems to be the problem  
 ![Screenshot from 2024-05-19 01-48-07](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/4/04e4a5e383c456d0511400763a821636a5f841f2.png)

> ![Screenshot from 2024-05-19 01-48-27](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/a/ba9544bfdd3d39ec08dbfaae6a3e14c5c793f87b.png)

In Homeyscript console, and with the AND ‘Run code’ card, there are no problems. As script output, you’d use the generated HS tags as shown in my Timeline card:

 ![Screenshot from 2024-05-19 01-41-53](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/a/ca5d6b59f9cdc5b3bb138480c3323aa97446e00d.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:** [May 19, 2024, 6:37am UTC](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/62 "2024-05-19T06:37:04Z")

</div>

Ah, I see, thanks Peter ! I have never used THEN, only as AND card 😉  
However in my case, the error message is quite weird …

`{"message":"Invalid token type: string. Expected: String"}`

…I do hope it’s not similar issue like with `await Homey.zigBee.getState();` vs `await Homey.zigbee.getState();`

Btw even this simple example return error…

![number](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/8/181a09fb37c7b4260428bbce7d4294d61709dfe3.png)  
 ![string](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/4/e4edde1edcec29c41b690f7d37946a51d6671c02.png)

_FYI - asking Athom if this is a bug or not_

**update it’s not a bug, script must be updated (but you can still use it just for THEN it will return the error but the variables gets updated**

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

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