Node Red - Manual Override

Hello
I’ve got Node Red automating my switches in my house, however there are times when I’d like to override a switch via a card on the home page. For example, lets say I have a Tasmota plug that node red is configured to turn on from 7 pm to 11 pm every night. Every once in a while I may want to turn that plug on at 4 pm. From my home page I locate the card the plug is on and use the slider button to turn it on. The lamp goes on, but only for a few seconds before turning off. I imagine that this is because 4 pm is outside the Node Red schedule? How can I set it up so that I can randomly override the Node Red schedule for this (or any) plug that I’ve programmed in Node Red? I don’t want to disable the Node Red flow as that would disrupt other plugs within the same flow.

Thanks in advance for any help that can be provided.

This actually depends on the flows you have made. This particular thing can be easily avoided. Can you share your flow?

This can be done with a function within the nodered itself. Just use the expose to HA option in event state node. But this will work only if you have installed the nodered custom integration.

You need to post the automation for us to help

You can set the “Expose to Home Assistant” checkbox. This creates a switch in HA (provides you have the NodeRed integration setup). Then, you can just toggle on and off the switch and that will disable ONLY the event node and nothing else in the flow.

Hello
Thank you for your reply. Please see the flow for my “Sunroom” lamp.

Hello
Would someone be kind enough to comment on where the “events: state node” would fit into my “Sunroom Plug” sequence? Thanks in advance.

BIg timer is the problem. Use inject nodes, they will only send the message at the turn on/off time.

[{"id":"defaeff2.8bcd98","type":"api-call-service","z":"d6a46901.ebee1","name":"turn on service","server":"","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":720,"y":1020,"wires":[[]]},{"id":"bd5b8f08.16c708","type":"api-call-service","z":"d6a46901.ebee1","name":"turn off service","server":"","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":720,"y":1120,"wires":[[]]},{"id":"d79fbef7.8eece8","type":"inject","z":"d6a46901.ebee1","name":"on at 4pm","props":[{"p":"payload"}],"repeat":"","crontab":"00 16 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":420,"y":1020,"wires":[["defaeff2.8bcd98"]]},{"id":"889dd4b6.71999","type":"inject","z":"d6a46901.ebee1","name":"off at 11pm","props":[{"p":"payload"}],"repeat":"","crontab":"00 23 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":420,"y":1120,"wires":[["bd5b8f08.16c708"]]}]
1 Like

Hello
Thanks for the response. Can an “inject node” turn an outside light on at sunset and off at sunrise? I don’t see that in the setting. Also will it allow for a manual override of the switch from HA? I prefer to work with the GUI and not code. Is there a GUI solution for me?

For the outside lights use the sun node. You can just turn on the light switch, it will stay on, there is no need for anything else.

[{"id":"fb01af2f.2e3fd8","type":"sunrise","z":"24e54e48.fd06f2","name":"","lat":"","lon":"","start":"sunrise","end":"sunset","soff":0,"eoff":0,"x":720,"y":460,"wires":[[],[]]}]

So is this how the sequence would look?

That’s not the sun node I posted. That is sun events. Please import the code I posted if you can’t find it.

Here is a working example. To import the code go to the hamburger menu on the right, choose import and paste the code.

[{"id":"6cd1edae.a9b8b4","type":"sunrise","z":"24e54e48.fd06f2","g":"7873948.5ba166c","name":"","lat":"","lon":"","start":"sunriseEnd","end":"sunsetStart","soff":0,"eoff":0,"x":150,"y":640,"wires":[[],["1d5683bc.0b6ff4"]]},{"id":"8e32aab.322cad8","type":"api-call-service","z":"24e54e48.fd06f2","g":"7873948.5ba166c","name":"yard lights off","server":"","version":1,"debugenabled":true,"service_domain":"light","service":"turn_off","entityId":"light.7532182798f4abbe149a, light.75321827cc50e3f23ae4","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":680,"wires":[[]]},{"id":"e78523.b1d82ae","type":"api-call-service","z":"24e54e48.fd06f2","g":"7873948.5ba166c","name":"yard lights on","server":"","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.7532182798f4abbe149a, light.75321827cc50e3f23ae4","data":"{\"brightness\":46,\"color_temp\":250}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":620,"wires":[[]]},{"id":"1d5683bc.0b6ff4","type":"switch","z":"24e54e48.fd06f2","g":"7873948.5ba166c","name":"on off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":640,"wires":[["e78523.b1d82ae","41c8651e.b0337c"],["8e32aab.322cad8","b009e755.bb2a1"]]},{"id":"b009e755.bb2a1","type":"api-call-service","z":"24e54e48.fd06f2","g":"7873948.5ba166c","name":"rear lights off","server":"","version":1,"debugenabled":true,"service_domain":"switch","service":"turn_off","entityId":"switch.basement_rear","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":530,"y":700,"wires":[[]]},{"id":"41c8651e.b0337c","type":"api-call-service","z":"24e54e48.fd06f2","g":"7873948.5ba166c","name":"rear lights on","server":"","version":1,"debugenabled":true,"service_domain":"switch","service":"turn_on","entityId":"switch.basement_rear","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":530,"y":580,"wires":[[]]}]

So I’ve got seven lights that all go on at sunset and off at various times; one of them at 1 AM the next day. Do I need to create seven separate events using this code and fill in the correct “id” number along with the lat and long?

For future users encountering this, I solved this by creating a sort of filter.

Simple example: my Christmas Tree. I wanted a ZigBee plug to turn on at sunset, off at sunrise, but for custom states to be retained (e.g. if someone wanted to see the lights during the day, or turn it off at night). As an extra challenge, the range of this plug to the nearest router/repeater isn’t great, so sometimes it takes a few "on"s to get it to toggle.

Both “timeswitch” and “BigTimer” from node-contrib send events over and over to indicate that the state should be on (1) or off (0). That’s why it only respects manual override for a few seconds.

What I did to solve this was use the function node with the below JS:

const COUNT = "count";
const MSG = "msg.payload";
const MAX_REPEATS = 3;

let lastMsg = flow.get(MSG);
let current = flow.get(COUNT);

if (!current || !lastMsg || (msg != lastMsg))
{
    node.log("current is " + current + ", lastMsg is " + lastMsg + ", msg is " + msg + "; setting current to 0");
    current = 0;
}

flow.set(MSG, msg.payload)

current++;

node.log("current incremented: " + current);

if (current >= MAX_REPEATS)
{
    // discard message
    node.log("discarding repeat message: " + msg.payload);
    return;
}

flow.set(COUNT, current);
return msg;

And I stuck it between timeswitch (BigTimer, in your case) and the first switch mode. Now it repeats the command 3 times, then discards any future sends. I can turn the tree off/on at will, and the scheduled events will only happen (3 times) when they’re actually scheduled.

[{"id":"8cbe0f32439a2fb4","type":"group","z":"e3e0819e890caeb6","name":"Christmas Tree","style":{"stroke":"#ff0000","fill":"#c8e7a7","label":true},"nodes":["60c42fcdcab59db6","09226899caae678b","2608a78c43467dcf","d89f873ffcc7785f","09990beaadcd0c7c"],"x":14,"y":959,"w":692,"h":162},{"id":"60c42fcdcab59db6","type":"timeswitch","z":"e3e0819e890caeb6","g":"8cbe0f32439a2fb4","name":"On at sunset, Off at sunrise","mytopic":"","lat":"43.00000","lon":"-78.00000","starttime":"6000","endtime":"5000","timezone":"America/New_York","duskoff":"0","dawnoff":"-360","sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"x":170,"y":1000,"wires":[["09990beaadcd0c7c"]]},{"id":"09226899caae678b","type":"switch","z":"e3e0819e890caeb6","g":"8cbe0f32439a2fb4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":1080,"wires":[["2608a78c43467dcf"],["d89f873ffcc7785f"]]},{"id":"2608a78c43467dcf","type":"api-call-service","z":"e3e0819e890caeb6","g":"8cbe0f32439a2fb4","name":"Turn on Christmas Tree","server":"a5439baab5b3df3f","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":["family_room"],"deviceId":["0fa9357a14772f41009038b2f9128553"],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":570,"y":1000,"wires":[[]]},{"id":"d89f873ffcc7785f","type":"api-call-service","z":"e3e0819e890caeb6","g":"8cbe0f32439a2fb4","name":"Turn off Christmas Tree","server":"a5439baab5b3df3f","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":["family_room"],"deviceId":["0fa9357a14772f41009038b2f9128553"],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":570,"y":1080,"wires":[[]]},{"id":"09990beaadcd0c7c","type":"function","z":"e3e0819e890caeb6","g":"8cbe0f32439a2fb4","name":"repeat message","func":"const COUNT = \"count\";\nconst MSG = \"msg.payload\";\nconst MAX_REPEATS = 3;\n\nlet lastMsg = flow.get(MSG);\nlet current = flow.get(COUNT);\n\nif (!current || !lastMsg || (msg != lastMsg))\n{\n    node.log(\"current is \" + current + \", lastMsg is \" + lastMsg + \", msg is \" + msg + \"; setting current to 0\");\n    current = 0;\n}\n\nflow.set(MSG, msg.payload)\n\ncurrent++;\n\nnode.log(\"current incremented: \" + current);\n\nif (current >= MAX_REPEATS)\n{\n    // discard message\n    node.log(\"discarding repeat message: \" + msg.payload);\n    return;\n}\n\nflow.set(COUNT, current);\nreturn msg;","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\nflow.set(\"count\", 0);","finalize":"","libs":[],"x":140,"y":1080,"wires":[["09226899caae678b"]]},{"id":"a5439baab5b3df3f","type":"server","name":"Home Assistant","version":4,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m"}]

EDIT 2022-12-17: Fixed a bug in my code.

Hello Jesse
I had a similar issue with some of my light switches in that they would operate exactly the same as your Christmas Tree example; on at sunset off at sunrise yet if anyone wanted to turn the light on during the day, it would go off after 30 seconds. What I did to solve the problem was un-check “repeat output” on the Node Red Big Timer card. That solved my issue.

image

1 Like

Hi Michael! Yup, that would do it. I guess I missed that when I last used BigTimer. I like timeswitch for being a bit smaller. Glad you found a solution.