We can not assess the values of variables y
and w
so it is not possible to know why the conditional statement is not working as you expect. If you share the flow it will be easier to troubleshoot your flow.
If I understood correctly you want to select among three different objects based on the status of two variables. If this is correct then the conditional statement could be as simple as:
let select = pause ? 0 : enable ? 1 : 2;
The main function would in such case looks like:
let obj = [
{"payload" : "a", "timeout" : "b", "warning" : "c"},
{"payload" : "d", "timeout" : "e", "warning" : "f"},
{"payload" : "g", "timeout" : "h", "warning" : "i"}
]
let enable = flow.get("enable");
let pause = flow.get("pause");
// obj[0] => pause=true
// obj[1] => pause=false , enable=true
// obj[2] => pause=false , enable=false
let select = pause ? 0 : enable ? 1 : 2;
// show status
node.status({text:`pause=${pause} , enable=${enable}`});
msg.payload = obj[select];
return msg;
and the flow would be like (need however some additional nodes for the initialization)
[{"id":"2e301f7e.715e6","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d00582c1.eec9b","type":"ui_switch","z":"2e301f7e.715e6","name":"Enable Timeout","label":"Enable Timeout","tooltip":"","group":"7fae6457.6b198c","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":260,"y":80,"wires":[["48f39e0d.4fc42"]]},{"id":"a04ab26a.bd971","type":"ui_switch","z":"2e301f7e.715e6","name":"Pause countdown","label":"Pause countdown","tooltip":"","group":"7fae6457.6b198c","order":3,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":270,"y":180,"wires":[["d14a3ab4.3cac08"]]},{"id":"46eae271.15603c","type":"ui_slider","z":"2e301f7e.715e6","name":"Timeout","label":"Timeout","tooltip":"","group":"7fae6457.6b198c","order":2,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":10,"step":1,"x":240,"y":260,"wires":[["53ea1b5b.a10704"]]},{"id":"48f39e0d.4fc42","type":"change","z":"2e301f7e.715e6","name":"Enable","rules":[{"t":"set","p":"enable","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":80,"wires":[["aee265d0.cd2c88"]]},{"id":"d14a3ab4.3cac08","type":"change","z":"2e301f7e.715e6","name":"Pause","rules":[{"t":"set","p":"pause","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":180,"wires":[["aee265d0.cd2c88"]]},{"id":"53ea1b5b.a10704","type":"change","z":"2e301f7e.715e6","name":"Timeout","rules":[{"t":"set","p":"timeout","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":260,"wires":[["aee265d0.cd2c88"]]},{"id":"a2967531.5d67a8","type":"comment","z":"2e301f7e.715e6","name":"obj[0] => pause=true , obj[1] => pause=false , enable=true , obj[2] => pause=false , enable=false","info":"","x":390,"y":460,"wires":[]},{"id":"bec74d96.58821","type":"comment","z":"2e301f7e.715e6","name":"obj[0] = {\"payload\" : \"a\", \"timeout\" : \"b\", \"warning\" : \"c\"}","info":"","x":520,"y":500,"wires":[]},{"id":"ef8b295d.ff0aa8","type":"comment","z":"2e301f7e.715e6","name":"obj[1] = {\"payload\" : \"d\", \"timeout\" : \"e\", \"warning\" : \"f\"}","info":"","x":520,"y":540,"wires":[]},{"id":"d69e98e4.f1d158","type":"comment","z":"2e301f7e.715e6","name":"obj[2] = {\"payload\" : \"g\", \"timeout\" : \"h\", \"warning\" : \"i\"}","info":"","x":520,"y":580,"wires":[]},{"id":"18310a37.45dab6","type":"function","z":"2e301f7e.715e6","name":"Select Object","func":"let obj = [\n {\"payload\" : \"a\", \"timeout\" : \"b\", \"warning\" : \"c\"},\n {\"payload\" : \"d\", \"timeout\" : \"e\", \"warning\" : \"f\"},\n {\"payload\" : \"g\", \"timeout\" : \"h\", \"warning\" : \"i\"}\n ]\n\n\nlet enable = flow.get(\"enable\");\nlet pause = flow.get(\"pause\");\n\n// obj[0] => pause=true\n// obj[1] => pause=false , enable=true\n// obj[2] => pause=false , enable=false\n\nlet select = pause ? 0 : enable ? 1 : 2;\n\n// show status\nnode.status({text:`pause=${pause} , enable=${enable}`});\n\nmsg.payload = obj[select];\n\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":360,"wires":[["2c537433.6c97cc"]]},{"id":"2c537433.6c97cc","type":"debug","z":"2e301f7e.715e6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":360,"wires":[]},{"id":"aee265d0.cd2c88","type":"link out","z":"2e301f7e.715e6","name":"","links":["52b163.b4590e9c"],"x":655,"y":180,"wires":[]},{"id":"52b163.b4590e9c","type":"link in","z":"2e301f7e.715e6","name":"","links":["aee265d0.cd2c88"],"x":395,"y":360,"wires":[["18310a37.45dab6"]]},{"id":"fcdf7959.8ddc38","type":"inject","z":"2e301f7e.715e6","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":60,"wires":[["d00582c1.eec9b"]]},{"id":"717fa7e9.18a008","type":"inject","z":"2e301f7e.715e6","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":160,"wires":[["a04ab26a.bd971"]]},{"id":"b6e32029.b8eca","type":"inject","z":"2e301f7e.715e6","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":100,"wires":[["d00582c1.eec9b"]]},{"id":"48cc07b0.0d13a8","type":"inject","z":"2e301f7e.715e6","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":200,"wires":[["a04ab26a.bd971"]]},{"id":"7fae6457.6b198c","type":"ui_group","z":"","name":"G1","tab":"d12a40ce.f7ebd","disp":true,"width":"12","collapse":false},{"id":"d12a40ce.f7ebd","type":"ui_tab","z":"","name":"T1","icon":"dashboard","disabled":false,"hidden":false}]