I want to replace two nodes of "changes" with one node of "function". But, I do something wrong.
Could you help me, please!
Idea is enable / disable the dashboard switch by "function" node.
my code of "function" node.
if (msg.payload === "On") {
msg.payload = {'enabled':"true"};
return [ msg ];
}
else if (msg.payload === "Off"){
msg.payload = {'enabled':"false"};
return [ msg ];
}
else {
return [ null ];
}
my flow
[{"id":"c22901ee.cddb8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4c18cc5b.2438a4","type":"ui_switch","z":"c22901ee.cddb8","name":"","label":"switch","tooltip":"","group":"298a6214.c57fde","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":550,"y":300,"wires":[[]]},{"id":"b2723bce.8e2718","type":"change","z":"c22901ee.cddb8","name":"Enable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":200,"wires":[[]]},{"id":"4dc147c7.dfb608","type":"change","z":"c22901ee.cddb8","name":"Disable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":260,"wires":[[]]},{"id":"90d39172.e8eef","type":"inject","z":"c22901ee.cddb8","name":"Enable","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"On","payloadType":"str","x":150,"y":280,"wires":[["b2723bce.8e2718","a781deac.dd63d"]]},{"id":"dea5ceb5.fced3","type":"inject","z":"c22901ee.cddb8","name":"Disable","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Off","payloadType":"str","x":150,"y":340,"wires":[["4dc147c7.dfb608","a781deac.dd63d"]]},{"id":"533e2cb3.14e894","type":"debug","z":"c22901ee.cddb8","name":"222222","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":400,"wires":[]},{"id":"a781deac.dd63d","type":"function","z":"c22901ee.cddb8","name":"","func":"\n\nif (msg.payload === \"On\") { \n msg.payload = {'enabled':\"true\"};\n return [ msg ];\n} \nelse if (msg.payload === \"Off\"){ \n msg.payload = {'enabled':\"false\"};\n return [ msg ];\n}\nelse { \n return [ null ];\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":360,"wires":[["533e2cb3.14e894","4c18cc5b.2438a4"]]},{"id":"298a6214.c57fde","type":"ui_group","name":"A1","tab":"cf795f11.f1c7b","order":1,"disp":true,"width":"6","collapse":false},{"id":"cf795f11.f1c7b","type":"ui_tab","name":"TEST","icon":"dashboard","order":1,"disabled":false,"hidden":false}]