PT2262-in to boolean true

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!

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

There are quite a few ways...

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

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: ....

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

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

[{"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":[]}]
1 Like

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

[{"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}]

try something like this

[{"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"]]}]
1 Like

Hello E1cid,

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

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!

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.

1 Like

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