# Payload message conversion

**URL:** <https://discourse.nodered.org/t/payload-message-conversion/49356>\
**Category:** Dashboard\
**Created:** [4 August 2021 22:11 UTC](https://discourse.nodered.org/t/payload-message-conversion/49356 "2021-08-04T22:11:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruinsmm](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@bruinsmm](https://discourse.nodered.org/u/bruinsmm)\
**Post date:** [4 August 2021 22:11 UTC](https://discourse.nodered.org/t/payload-message-conversion/49356/1 "2021-08-04T22:11:42Z")

</div>

I have a motion sensor. When there is motion ik got the following message:  
 ![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f30ce0d464c5dc48fd13c363e2cd3f4120f9ed9.png)

How can i translate the message to simple payload = "ON" or "OFF".

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 August 2021 22:22 UTC](https://discourse.nodered.org/t/payload-message-conversion/49356/2 "2021-08-04T22:22:43Z")

</div>

Try this code in a function node.

```auto
msg.payload = msg.payload.object.newValue ? "ON" : "OFF";
return msg;

```

maybe typo's as it's hard to copy and paste from an image.

---

<div class="post-metadata">

**Author:** ![bruinsmm](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@bruinsmm](https://discourse.nodered.org/u/bruinsmm)\
**Post date:** [5 August 2021 09:41 UTC](https://discourse.nodered.org/t/payload-message-conversion/49356/3 "2021-08-05T09:41:12Z")

</div>

Thanks @E1cid. Your solution works.

I got only double messages on the output of the debug node, because the motion sensor returns values of 2 properties the same time. I have fixed this with Switch Node to pass only 1 property.

---

<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 August 2021 09:41 UTC](https://discourse.nodered.org/t/payload-message-conversion/49356/4 "2021-08-19T09:41:29Z")

</div>

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