# PT2262-in to boolean true

**URL:** <https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838>\
**Category:** General\
**Created:** [29 December 2021 13:27 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838 "2021-12-29T13:27:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![NR-Beginner](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@NR-Beginner](https://discourse.nodered.org/u/NR-Beginner)\
**Post date:** [29 December 2021 13:27 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/1 "2021-12-29T13:27:57Z")

</div>

hello insider, a newbie here ....

i am stuck. i have a 4 channel remote here, i would like to use it to control 4 philips Hue smartplugs.

The smartplugs only respond to boolean true or false  
I recognize by PT2262-in the codes of the remote control, make there the payload aon and aoff (for channel A of the remote control). Then I wanted to convert aon to true, or aoff to false.  
This does not work - what am I doing wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [29 December 2021 13:39 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/2 "2021-12-29T13:39:07Z")

</div>

It would be easier to understand your problem if you post your flow here.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 December 2021 13:42 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/3 "2021-12-29T13:42:21Z")

</div>

There are quite a few ways...

For example: in a function node you could do...

```auto
if(msg.payload === "aon") {
  msg.payload = true;
} else if (msg.payload === "aoff") {
  msg.payload = false;
} else {
  return null; //dont send msg to next node
}
return msg;

```

Or: with a 1 switch (2 comparisons) and 2 change nodes (1 sets msg.payload to true, the other sets msg.payload to false).

Or: a change node with JSONata expression

Or: ....

---

<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:** [29 December 2021 13:53 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/4 "2021-12-29T13:53:38Z")

</div>

Adding to Steve's response, if you want to be able to differentiate between the channels to i would use substr() to work out channel and on/off

```auto
let on_off = msg.payload.substr(1);
msg.channel = msg.payload.substr(0,1);
if(on_off === "on"){
    msg.payload = true;
}else if(on_off === "off"){
    msg.payload = false;
}else{
    msg = null;
}
return msg;

```

This would work for "bon", "con" etc  
example flow

```auto
[{"id":"e70ef5b9.bf4af8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"aon","payloadType":"str","x":130,"y":300,"wires":[["424ab351.4a20ec"]]},{"id":"424ab351.4a20ec","type":"function","z":"c791cbc0.84f648","name":"","func":"let on_off = msg.payload.substr(1);\nmsg.channel = msg.payload.substr(0,1);\nif(on_off ===\"on\"){\n msg.payload = true;\n}else if(on_off === \"off\"){\n msg.payload = false\n}else{\n msg = null;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":300,"wires":[["9a6e0a0d.52834"]]},{"id":"3c3b397c.849ee6","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"aoff","payloadType":"str","x":120,"y":340,"wires":[["424ab351.4a20ec"]]},{"id":"9a6e0a0d.52834","type":"switch","z":"c791cbc0.84f648","name":"","property":"channel","propertyType":"msg","rules":[{"t":"eq","v":"a","vt":"str"},{"t":"eq","v":"b","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":300,"wires":[["f7ba02e5.9de63"],["95b09e83.cfbe38"]]},{"id":"f7ba02e5.9de63","type":"debug","z":"c791cbc0.84f648","name":"a","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":300,"wires":[]},{"id":"95b09e83.cfbe38","type":"debug","z":"c791cbc0.84f648","name":"b","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":340,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![NR-Beginner](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@NR-Beginner](https://discourse.nodered.org/u/NR-Beginner)\
**Post date:** [29 December 2021 15:54 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/5 "2021-12-29T15:54:05Z")

</div>

my first idea as newbie (dont laugh pls :))

```auto
[{"id":"91a2f6d9ce453d40","type":"rfx-PT2262-in","z":"af7fe8c3b5f717ca","name":"A","port":"38cca044.fc7bd","deviceList":"0dd3cb0011ea3ee6","topicSource":"all","topic":"","x":370,"y":300,"wires":[["9dbfc7e2ff95fa51","21edfdc1c69599d7"]]},{"id":"25abeab92024676f","type":"hue-light","z":"af7fe8c3b5f717ca","name":"Hue smart plug 4","bridge":"36b93868f3cfa2da","lightid":"12","colornamer":true,"skipevents":false,"universalevents":false,"x":950,"y":320,"wires":[[]]},{"id":"9dbfc7e2ff95fa51","type":"change","z":"af7fe8c3b5f717ca","name":"","rules":[{"t":"set","p":"aon","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":280,"wires":[["25abeab92024676f"]]},{"id":"21edfdc1c69599d7","type":"change","z":"af7fe8c3b5f717ca","name":"","rules":[{"t":"set","p":"aoff","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":340,"wires":[["25abeab92024676f"]]},{"id":"ccdee248a0c38057","type":"inject","z":"af7fe8c3b5f717ca","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"true","payload":"true","payloadType":"bool","x":890,"y":80,"wires":[["25abeab92024676f"]]},{"id":"27b442fca0de0fe0","type":"inject","z":"af7fe8c3b5f717ca","name":"Off","props":[{"p":"payload"},{"p":"topic","v":"false","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":890,"y":120,"wires":[["25abeab92024676f"]]},{"id":"e87eaae6d7ba6b98","type":"comment","z":"af7fe8c3b5f717ca","name":"Manual on/off","info":"Manual on/off","x":730,"y":80,"wires":[]},{"id":"8daadd6f79d9b8f1","type":"comment","z":"af7fe8c3b5f717ca","name":"Hex -> aon -> true","info":"","x":630,"y":240,"wires":[]},{"id":"f592fcd155abac7c","type":"comment","z":"af7fe8c3b5f717ca","name":"receive hex code from remote control, channel a","info":"","x":240,"y":260,"wires":[]},{"id":"38cca044.fc7bd","type":"rfxtrx-port","port":"/dev/ttyUSB0","rfyVenetianMode":"US"},{"id":"0dd3cb0011ea3ee6","type":"PT2262-device-list","name":"Kanal A","devices":[{"device":["PT2262"],"payload":"aoff","rawData":"0x104554","pulseWidth":350},{"device":["PT2262"],"payload":"aon","rawData":"0x104551","pulseWidth":350}]},{"id":"36b93868f3cfa2da","type":"hue-bridge","name":"HueMagic Bridge","bridge":"192.168.1.23","key":"IwnC3vTIm1b5YA9x1YgVMeFJ9MqvWBHPlJHFejnf","interval":"3000","disableupdates":false}]

```

---

<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:** [29 December 2021 18:24 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/6 "2021-12-29T18:24:21Z")

</div>

try something like this

```auto
[{"id":"c2b64a13.1642d","type":"rfx-PT2262-in","z":"c791cbc0.84f648","name":"A","port":"38cca044.fc7bd","deviceList":"0dd3cb0011ea3ee6","topicSource":"all","topic":"","x":350,"y":1040,"wires":[["d6ad6645.0e1fe8"]]},{"id":"d6ad6645.0e1fe8","type":"function","z":"c791cbc0.84f648","name":"","func":"let on_off = msg.payload.substr(1);\nmsg.channel = msg.payload.substr(0,1);\nif(on_off ===\"on\"){\n msg.payload = true;\n}else if(on_off === \"off\"){\n msg.payload = false\n}else{\n msg = null;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":1040,"wires":[["7a9bfbbb.a4ea3c"]]},{"id":"7a9bfbbb.a4ea3c","type":"switch","z":"c791cbc0.84f648","name":"","property":"channel","propertyType":"msg","rules":[{"t":"eq","v":"a","vt":"str"},{"t":"eq","v":"b","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":760,"y":1040,"wires":[["6078714a.39bbd8"],[]]},{"id":"8201962.a8b5fe8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"aoff","payloadType":"str","x":490,"y":1000,"wires":[["d6ad6645.0e1fe8"]]},{"id":"1934adb.f731052","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"aon","payloadType":"str","x":510,"y":960,"wires":[["d6ad6645.0e1fe8"]]},{"id":"6078714a.39bbd8","type":"hue-light","z":"c791cbc0.84f648","name":"Hue smart plug 4","bridge":"36b93868f3cfa2da","lightid":"12","colornamer":true,"skipevents":false,"universalevents":false,"x":930,"y":1140,"wires":[[]]},{"id":"144f5f01.5430d1","type":"inject","z":"c791cbc0.84f648","name":"Off","props":[{"p":"payload"},{"p":"topic","v":"false","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":690,"y":1180,"wires":[["6078714a.39bbd8"]]},{"id":"cbd76399.1850a","type":"inject","z":"c791cbc0.84f648","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"true","payload":"true","payloadType":"bool","x":690,"y":1140,"wires":[["6078714a.39bbd8"]]}]

```

---

<div class="post-metadata">

**Author:** ![NR-Beginner](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@NR-Beginner](https://discourse.nodered.org/u/NR-Beginner)\
**Post date:** [29 December 2021 19:59 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/7 "2021-12-29T19:59:25Z")

</div>

Hello E1cid,

thank you very much! But I can only test it tomorrow, the kids have to go to bed 🙂

How do I do it if I then include the other 3 channels of the remotes? I would simply adapt to the end of your flow each the Hue Smartplugs 1-4 but how do I teach the flow that it then works for channel B etc.?  
So then bon, boff, con, coff etc.  
Under the "function" node is always only on = true or off = false. But just not differentiated between the individual channels A - D? How would that work?

Thanks to you and all who help! Unfortunately, I hardly find the time to practice etc.. - but it is fun when you understand some things!

---

<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:** [29 December 2021 20:13 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/8 "2021-12-29T20:13:31Z")

</div>

THe function node splits the incoming "aon" to  
msg.channel = "a"  
on\_off = "on"  
It will do same for "bon" or "doff" etc

The switch node then checks msg.channel and directs it to the path required ( at moment just a & b)

To add more just add more options in the switch node and add the hue smart plug to each output.

---

<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:** [27 February 2022 20:13 UTC](https://discourse.nodered.org/t/pt2262-in-to-boolean-true/55838/9 "2022-02-27T20:13:54Z")

</div>

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