# Notification when Aqara binary senors went offline

**URL:** https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081
**Category:** General
**Created:** [19 September 2020 13:30 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081 "2020-09-19T13:30:46Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)
#### Post date: [19 September 2020 13:30 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/1 "2020-09-19T13:30:46Z")

</div>

Hey guys!  
First of all I have to confess, I'm a noob 🙂 I get things working most of the time but if it comes to coding it's over for me 🙂

What I'm trying to do is a "watchdog" for my Zigbee Sensors (Aqara Door/Window Sensors). I thought about a Timer which activates every 10 minutes the phoscon get node for the specific sensor. The node provides then the timestamp-value for "last updated".  
As a next step I thought about a function node which compares the "last updated" timestamp with the current time, and if the time difference is higher than one or two hours it notifies me via my Telegram node or sth.  
BTW: Do I need to do some timezone corrections? It seems to me that the timezone is not as I initially adjusted it in my HomeAssistant / NodeRed confguration.

Does this approach make sense to you and if so, can you help me with the function node?

Thank you in Advance  
Alex

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 September 2020 13:56 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/2 "2020-09-19T13:56:34Z")

</div>

If you have a point in your flows where you have regular messages coming in and want to detect the fact that no messages arrive within a given time, then connect them to a Trigger node, set to Send Nothing then after 60 minutes (or whatever) send the timeout message. Set Extend Delay on new message and that will mean that it keeps restarting the timer every time a new message comes in. If no messages arrive for 60 minutes then it will send the message.  
If you want it to fire 60 minutes after a reboot or node-red restart if no data comes in then also connect an inject node set to inject once on startup and that will set the timer going immediately.

---

<div class="post-metadata">

### Author: ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)
#### Post date: [19 September 2020 16:50 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/3 "2020-09-19T16:50:56Z")

</div>

Hay Thank you Colin! Unfortunately I have to "request" the sensors. And then I have to examine the payload for the "last updated" state. The sensors don't fire any payload as far as I see if not requested actively or if no state change happens.

Regards

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 September 2020 16:58 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/4 "2020-09-19T16:58:39Z")

</div>

Add a debug node and show us what comes back from the sensor.

---

<div class="post-metadata">

### Author: ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)
#### Post date: [19 September 2020 17:13 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/5 "2020-09-19T17:13:37Z")

</div>

Here you are:

```auto
{"payload":{"lastupdated":"2020-09-19T16:40:30.610","open":false},
"payload_in":1600535428613,
"meta":{"config":{"battery":100,
"on":true,
"reachable":true,
"temperature":2600},
"ep":1,
"etag":"d2864032573db3fb9bbd19ee0d1951bc",
"lastseen":"2020-09-19T16:40:30.610","manufacturername":"LUMI",
"modelid":"lumi.sensor_magnet.aq2",
"name":"Türkontakt-tue",
"state":{"lastupdated":"2020-09-19T16:40:30.610",
"open":false},
"swversion":"20161128",
"type":"ZHAOpenClose",
"uniqueid":"00:15:8d:00:88:48:89:78-01-0006",
"device_type":"sensors",
"device_id":5},
"_msgid":"d95a17.f06cc8"}

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 September 2020 17:22 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/6 "2020-09-19T17:22:37Z")

</div>

Is that a UTC date/time or local timezone?

---

<div class="post-metadata">

### Author: ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)
#### Post date: [19 September 2020 17:31 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/7 "2020-09-19T17:31:33Z")

</div>

I guess it's a UTC Time, but I don't know why. I have my local Time defined everywhere...

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 September 2020 19:14 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/8 "2020-09-19T19:14:00Z")

</div>

> [@terminus](#):
>
> guess it's a UTC Time

Good, you would be in trouble if it was local time. What would happen when there was a DST change for example. Have a look at the JavaScript Date type. Probably you can feed that string straight into the Date constructor to give you a JavaScript Date, which you can then then subtract from the current time to give you how long ago it was. Start with a function node and see if you conduct the date object, put that in the message payload for the moment and feed it into a debug node to see what it says.

---

<div class="post-metadata">

### Author: ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)
#### Post date: [19 September 2020 19:32 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/9 "2020-09-19T19:32:13Z")

</div>

Sorry but I have no clue what the function has to look like. Can you help me?

Thank you!

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 September 2020 19:43 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/10 "2020-09-19T19:43:42Z")

</div>

First do you know how to access the lastupdated timestamp in a function node? If not then read the docs page Working with Messages and see if you can work out how to get at the timestamp.  
Once you have done that then create a Date object from it and pass it out to go to a debug node to see what it shows. You will need something like

```auto
let lastupdated = new Date(....)
msg.payload = lastupdated
return msg

```

Replace the `...` with the reference to the lastupdated string from the data coming in, that you have worked out from the Working with Messages page.

**[Edit]** What node is that timestamp coming from (possibly node-red-contrib-somehing)? The timestamp should really have a Z on the end to show it is UTC, so whatever is providing the time is doing it in a non-standard way

---

<div class="post-metadata">

### Author: ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)
#### Post date: [19 September 2020 23:43 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/11 "2020-09-19T23:43:59Z")

</div>

The Time is coming from the Phoscon get Node. There is no Z but it is UTC.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 September 2020 06:44 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/12 "2020-09-20T06:44:01Z")

</div>

I can't find any reference to a phoscon node on the node red flows site, can you post a link to some information on it?

---

<div class="post-metadata">

### Author: ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)
#### Post date: [20 September 2020 16:47 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/13 "2020-09-20T16:47:36Z")

</div>

Yes of course, you have to search for:

node-red-contrib-deconz

Thank you 🙂

---

<div class="post-metadata">

### Author: ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)
#### Post date: [20 September 2020 16:53 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/14 "2020-09-20T16:53:08Z")

</div>

I use several aqara door /windows sensors together with a zigbee stick with a zigbee2mqtt firmware and I'm sure, that the aqara sensors send status informations once in a while even if the status does not change.

---

<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: [19 November 2020 16:53 UTC](https://discourse.nodered.org/t/notification-when-aqara-binary-senors-went-offline/33081/15 "2020-11-19T16:53:20Z")

</div>

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