HA Boolean input to switch function node

Hi,
I'm looking for an example of a function node (or other solution) to do the following

  • Use 7 x boolean inputs from HA ( 1 for each day of the week) to include or skip a run sequence for solenoids for an irrigation system.
  • If Monday boolean is set true, then run irrigation sequence if current day (based on timestamp) is Monday for example.
  • If boolean is set true for a particular day then run sequence otherwise stop sequence.

I cant seem to find a sequence of code to do this.
This is what I have tried so far. Any help would be great

[{"id":"a1d9470d505dd25e","type":"function","z":"45fa8931a015c6c3","name":"","func":"var d=new Date()\nvar weekday=d.getDay()\nif (weekday == 6 && \"input_boolean.saturday1\" == true)\n{\n    msg.payload =\"on\";\n{\n    elseif\n    msg.payload =\"off\";\n}\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":240,"wires":[[]]}]

If i understand correctly, this may do it

[{"id":"41b2542c.51d064","type":"inject","z":"b779de97.b1b46","name":"tues true","props":[{"p":"input_boolean.tuesday1","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":3960,"wires":[["a1d9470d505dd25e"]]},{"id":"a1d9470d505dd25e","type":"function","z":"b779de97.b1b46","name":"","func":"let days=[\"sunday1\",\"monday1\",\"tuesday1\",\"wednesday1\",\"thursday1\",\"friday1\",\"saturday1\"];\nvar d=new Date();\nvar weekday=d.getDay();\nif (msg.input_boolean[days[weekday]] === true){\n    msg.payload = \"on\";\n}\nelse{\n    msg.payload = \"off\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":3940,"wires":[["bb9973b6.41f25"]]},{"id":"bb9973b6.41f25","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":3960,"wires":[]},{"id":"8beb2fd3.f2252","type":"inject","z":"b779de97.b1b46","name":"tues false","props":[{"p":"input_boolean.tuesday1","v":"false","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":4000,"wires":[["a1d9470d505dd25e"]]},{"id":"c42ba777.47ae98","type":"inject","z":"b779de97.b1b46","name":"wed true","props":[{"p":"input_boolean.wednesday1","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":4060,"wires":[["a1d9470d505dd25e"]]}]

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