# Get mqtt value from motion detector, if occupancy is ON or OFF

**URL:** https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057
**Category:** General
**Created:** [25 July 2023 12:39 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057 "2023-07-25T12:39:43Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![EcarDK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ecardk/32/76058_2.png) [@EcarDK](https://discourse.nodered.org/u/EcarDK)
#### Post date: [25 July 2023 12:39 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/1 "2023-07-25T12:39:43Z")

</div>

links i use

> **[Philips 9290012607 control via MQTT | Zigbee2MQTT](https://www.zigbee2mqtt.io/devices/9290012607.html)**
>
> Integrate your Philips 9290012607 via Zigbee2MQTT with whatever smart home infrastructure you are using without the vendor's bridge or gateway.

When I set my Smart Button i do like this, and it work --\>

"mqtt in node"  
zigbee2mqtt/Hue Dimmer - Vitus/action

When I try whit my PH motion sensor I have try whit /get but it dont work?

zigbee2mqtt/MotionSensor/get

If I try  
zigbee2mqtt/MotionSensor/#

I get a list off objekt  
-object  
battery: 100  
illuminance: 25581  
illuminance\_lux: 361  
led\_indication: null  
linkquality: 52  
motion\_sensitivity: "high"  
occupancy: false  
occupancy\_timeout: 0  
temperature: 24.35

how do I get "occupancy: false" out as payload ?

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [25 July 2023 13:05 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/2 "2023-07-25T13:05:17Z")

</div>

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

### Author: ![EcarDK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ecardk/32/76058_2.png) [@EcarDK](https://discourse.nodered.org/u/EcarDK)
#### Post date: [25 July 2023 14:27 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/3 "2023-07-25T14:27:32Z")

</div>

Im sorry. I cant get it to work.

I see the part is payload.occupancy, but I dont get where and how to put it in a node

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [25 July 2023 14:32 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/4 "2023-07-25T14:32:35Z")

</div>

> [@EcarDK](#):
>
> payload.occupancy

Just send the msg into a change node like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a8278598785dceb99b241d2d24fc89509d11542a.png)

---

<div class="post-metadata">

### Author: ![EcarDK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ecardk/32/76058_2.png) [@EcarDK](https://discourse.nodered.org/u/EcarDK)
#### Post date: [25 July 2023 14:37 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/5 "2023-07-25T14:37:50Z")

</div>

ahh.. Thx alot

now it work

---

<div class="post-metadata">

### Author: ![EcarDK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ecardk/32/76058_2.png) [@EcarDK](https://discourse.nodered.org/u/EcarDK)
#### Post date: [25 July 2023 14:45 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/6 "2023-07-25T14:45:03Z")

</div>

hmm...

I dont understand why this dont work.

```auto
[{"id":"606fbab317657e8f","type":"debug","z":"fb88cea7421b6512","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":1800,"wires":[]},{"id":"b02dc8d4f8a27890","type":"mqtt in","z":"fb88cea7421b6512","name":"Bevægelsessensor Indendørs Stue","topic":"zigbee2mqtt/Bevægelsessensor Indendørs Stue/#","qos":"2","datatype":"auto-detect","broker":"711011c119463c3b","nl":false,"rap":true,"rh":0,"inputs":0,"x":180,"y":1820,"wires":[["4be81d97b9a99749"]]},{"id":"4be81d97b9a99749","type":"change","z":"fb88cea7421b6512","name":"occupancy","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.occupancy","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1820,"wires":[["1a6ed8fe17ba8d64"]]},{"id":"1a6ed8fe17ba8d64","type":"switch","z":"fb88cea7421b6512","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"str"},{"t":"eq","v":"false","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":1820,"wires":[["606fbab317657e8f"],["dd886caee32ab68b"]]},{"id":"dd886caee32ab68b","type":"debug","z":"fb88cea7421b6512","name":"debug 10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":1840,"wires":[]},{"id":"711011c119463c3b","type":"mqtt-broker","name":"MQTT Broker","broker":"192.168.1.106","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [25 July 2023 14:56 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/7 "2023-07-25T14:56:03Z")

</div>

You need to add a change node and then your switch needs to look for true or false

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7da6235356a718bf092d7c4a946d9b9b8823bca9.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/79f7833d5810c96691c57856e91ad5e02a926d25.png)

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [26 July 2023 02:13 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/8 "2023-07-26T02:13:00Z")

</div>

You need to edit your switch node for Boolean true / false rather than the string "true"

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0fe6e353d5a8ccab0ab13c8ee102bb91ad04e446.png)

---

<div class="post-metadata">

### Author: ![EcarDK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ecardk/32/76058_2.png) [@EcarDK](https://discourse.nodered.org/u/EcarDK)
#### Post date: [27 July 2023 08:13 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/9 "2023-07-27T08:13:52Z")

</div>

Thx to @Sean-McG and @ScheepersJohan

I got it to work.

Here are the solution, I use.

 ![Udklip](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/05f37548d09f7ba201b671396a74c58a784fb4d6.png)

```auto
[{"id":"73f8f43c36f461d3","type":"mqtt in","z":"fb88cea7421b6512","name":"Bevægelsessensor Badeværelse","topic":"zigbee2mqtt/Bevægelsessensor Badeværelse/#","qos":"2","datatype":"auto-detect","broker":"711011c119463c3b","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":1940,"wires":[["f2013d666b0a18d2"]]},{"id":"f2013d666b0a18d2","type":"change","z":"fb88cea7421b6512","name":"occupancy","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.occupancy","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1940,"wires":[["3d0918d628d76992"]]},{"id":"3d0918d628d76992","type":"switch","z":"fb88cea7421b6512","name":"","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":1940,"wires":[["85f542b4dcbaee10"],["57a5b288c83bfcbf"]]},{"id":"85f542b4dcbaee10","type":"debug","z":"fb88cea7421b6512","name":"false","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":1920,"wires":[]},{"id":"57a5b288c83bfcbf","type":"debug","z":"fb88cea7421b6512","name":"true","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":1960,"wires":[]},{"id":"711011c119463c3b","type":"mqtt-broker","name":"MQTT Broker","broker":"192.168.1.106","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

I set the occupancy time under zigbee2mqtt --\>

 ![Udklip](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f5b81a689ca86eea112123d27a3b828431f2a6e9.png)

---

<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 August 2023 08:14 UTC](https://discourse.nodered.org/t/get-mqtt-value-from-motion-detector-if-occupancy-is-on-or-off/80057/10 "2023-08-10T08:14:11Z")

</div>

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