# Display time since last zigbee2mqtt recieved

**URL:** https://discourse.nodered.org/t/display-time-since-last-zigbee2mqtt-recieved/37413
**Category:** General
**Created:** [12 December 2020 17:25 UTC](https://discourse.nodered.org/t/display-time-since-last-zigbee2mqtt-recieved/37413 "2020-12-12T17:25:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Chaos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chaos/32/107061_2.png) [@Chaos](https://discourse.nodered.org/u/Chaos)
#### Post date: [12 December 2020 17:25 UTC](https://discourse.nodered.org/t/display-time-since-last-zigbee2mqtt-recieved/37413/1 "2020-12-12T17:25:29Z")

</div>

Hi  
I am using the zigbee to mqtt admin panel in node red, to manage all my zigbee devices. This is a really good flow that displays all the infomation from zigbee devices and modify them. But one thing that would be useful thats not on the device status list is how long since the zigbee device was last heard from. If you look at the network map this infomation is available, but not on the general panel. so i thought i would add it.  
In the function that formats the data to be displayed in a ui-list node i added the following:-  
newPayload.push(newentry);  
newentry = {  
'title': 'Last Seen',  
'description':''+ msg.payload.lastSeen,  
'icon\_name': 'timer'  
};  
this displays the data as timestamp, but i need to subtract this number from the now timestamp and convert it to hours, mins, seconds. to display the time elapsed since the device was last seen.  
Is there a simple solution for this, i have tried Date(), toMillis etc, but can't figure it out.  
Chris.  
Now got this:  
'description':''+ (Date.parse(Date())-msg.payload.lastSeen/1000),  
Solved it ! A bit messy but it works.,,,,  
//Get hours from milliseconds  
var hours = (Date.parse(Date())-msg.payload.lastSeen)/ (1000_60_60);  
var absoluteHours = Math.floor(hours);  
var h = absoluteHours \> 9 ? absoluteHours : '0' + absoluteHours;

//Get remainder from hours and convert to minutes  
var minutes = (hours - absoluteHours) \* 60;  
var absoluteMinutes = Math.floor(minutes);  
var m = absoluteMinutes \> 9 ? absoluteMinutes : '0' + absoluteMinutes;

//Get remainder from minutes and convert to seconds  
var seconds = (minutes - absoluteMinutes) \* 60;  
var absoluteSeconds = Math.floor(seconds);  
var s = absoluteSeconds \> 9 ? absoluteSeconds : '0' + absoluteSeconds;  
msg.payload.last = h + " Hours, " + m +" Minutes and " + s +" Seconds ago";  
newPayload.push(newentry);  
newentry = {  
'title': 'Last Seen',  
'description':''+ msg.payload.last,  
'icon\_name': 'timer'  
};

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [10 February 2021 17:25 UTC](https://discourse.nodered.org/t/display-time-since-last-zigbee2mqtt-recieved/37413/2 "2021-02-10T17:25:32Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
