Manual override for switch/dropdown

Hi,

I found this solution to make a dropdown with Auto, manual off or manual on.

The issue is that only AUTO, and manual ON works. Off does not do anything.

I have tried for several hours to fix it now but cant seem to understand the reason why it does not work.

Anyone here has a clue? :smiley:

[{"id":"246bd678.de324a","type":"inject","z":"f954564f.03e718","name":"","topic":"","payload":"17","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":470,"y":1420,"wires":[["4d98c56f.a6b00c"]]},{"id":"4d98c56f.a6b00c","type":"function","z":"f954564f.03e718","name":"Fan control","func":"const Temp = msg.payload;\nconst override = global.get(\"AutoManual_switch\") || 0;\nconst fanstate = global.get(\"FanState\");\nif (override != 1) {\n    if (Temp <= 24 && fanstate !== 0) {\n        msg.payload = 0;\n        global.set(\"FanState\", msg.payload);\n        return msg;\n    } else if (Temp >= 27 && fanstate != 1) {\n        msg.payload = 1;\n        global.set(\"FanState\", msg.payload);\n        return msg;\n    } else {\n        return null;\n    }\n}","outputs":1,"noerr":0,"x":790,"y":1460,"wires":[["6e265f71.fb3a6","5bee4a8f.3e9474"]]},{"id":"2ad33de.326ce42","type":"change","z":"f954564f.03e718","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"Auto","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"Manual","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":1180,"wires":[["6be889a8.402848"]]},{"id":"5a900562.3c1bcc","type":"change","z":"f954564f.03e718","name":"Auto/Manual var","rules":[{"t":"set","p":"AutoManual_switch","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":1220,"wires":[[]]},{"id":"6879a6fc.3ca07","type":"change","z":"f954564f.03e718","name":"FanState var","rules":[{"t":"set","p":"FanState","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":1420,"wires":[[]]},{"id":"5bee4a8f.3e9474","type":"change","z":"f954564f.03e718","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"Off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":1360,"wires":[["714c6456.6ce8dc"]]},{"id":"714c6456.6ce8dc","type":"ui_text","z":"f954564f.03e718","group":"ad3e78a9.60d328","order":3,"width":"0","height":"0","name":"OnOFF Text","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1270,"y":1360,"wires":[]},{"id":"6be889a8.402848","type":"ui_text","z":"f954564f.03e718","group":"ad3e78a9.60d328","order":2,"width":"0","height":"0","name":"manualText","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1270,"y":1180,"wires":[]},{"id":"6e265f71.fb3a6","type":"debug","z":"f954564f.03e718","name":"Output to GPIO","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1080,"y":1540,"wires":[]},{"id":"edeb03a5.5ab118","type":"inject","z":"f954564f.03e718","name":"","topic":"","payload":"28","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":470,"y":1500,"wires":[["4d98c56f.a6b00c"]]},{"id":"938160bc.5804e","type":"function","z":"f954564f.03e718","name":"turn on override","func":"const override = global.get(\"AutoManual_switch\") || 0;\nif(override === 0){\n    msg.payload = 1;\n    return msg;\n} else {\n    return null;\n}","outputs":1,"noerr":0,"x":1080,"y":1280,"wires":[["2ad33de.326ce42","5a900562.3c1bcc"]]},{"id":"72310995.d00fe8","type":"ui_dropdown","z":"f954564f.03e718","name":"","label":"","tooltip":"","place":"Select option","group":"ad3e78a9.60d328","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"ON","value":1,"type":"num"},{"label":"OFF","value":0,"type":"num"},{"label":"AUTO","value":"auto","type":"str"}],"payload":"","topic":"","x":650,"y":1300,"wires":[["6b3f9be2.e49dec"]]},{"id":"6b3f9be2.e49dec","type":"switch","z":"f954564f.03e718","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"auto","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":1300,"wires":[["2ad33de.326ce42","9f506b80.990a6"],["938160bc.5804e","5bee4a8f.3e9474","6e265f71.fb3a6","6879a6fc.3ca07"]]},{"id":"d2c21975.fbb22","type":"comment","z":"f954564f.03e718","name":"Temp input","info":"","x":460,"y":1560,"wires":[]},{"id":"9f506b80.990a6","type":"change","z":"f954564f.03e718","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":1220,"wires":[["5a900562.3c1bcc"]]},{"id":"7f1fee39.4bfe8","type":"inject","z":"f954564f.03e718","name":"","topic":"","payload":"auto","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":470,"y":1300,"wires":[["72310995.d00fe8"]]},{"id":"ad3e78a9.60d328","type":"ui_group","z":"","name":"Text","tab":"85b04dc9.699e8","order":2,"disp":false,"width":"7","collapse":false},{"id":"85b04dc9.699e8","type":"ui_tab","z":"","name":"Remote View","icon":"dashboard","disabled":false,"hidden":false}]

Link to "parent" issue:
Parent issue

Start at the beginning of the flow and add debug nodes to watch what happens. Then you should be able to determine the point at which Off does not do what you expect.

For some reason the dropdown could not send the 0 value. Fixed it by setting ON to 1 OFF to 2

Ah yes a fix for that is currently in master. Not quite yet on npm.

1 Like

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