Hello everyone, I'm a newbie in Node Red, I am transitioning my home automation from SmartThings/WebCoRE to Home Assistant/Node-RED and I'm learning the essentials.
As I already have many automations that work fantastically, I'm trying to migrate one by one.
I'm not a coder, I sometimes understand some of it, and I'm eager to learn, but I would prefer to avoid function nodes for the moment. I'm planning to start learning some JS to be more familiar with it, but I'm trying to go one step at a time.
I was recently posting in the Home Assistant Community forum, but I also found some great info in this forum, so I wanted to bring this question here:
The main idea of what I want to achieve, is that I have two switches, one physical and one virtual, and whenever one of them is activated, I want the other one to mimic the action.
There are a couple of reason for wanting this, the main one being that I want to put Sonoff switches behind all of my houselights, and some of them already have Hue bulbs. So I want my automations to activate the virtual switch, and this virtual switch will then turn on or off the Sonoff switch and send the RGB/brightness commands to the bulb.
I know I could make the Sonoff switches just work as “remotes” and not actually cut the power to the bulbs, but I’ve done some tests and I don’t like the delays and fade times.
Also, I want the nodes to be easily editable, I’ve tried this in my first Node Red automation where I just set a device list on the Inject or Event state node, and the rest of the nodes pick the device names from the messages. This allows me to use the same node block with different devices without needing to edit a lot of things every time I copy and paste the block.
As this setup can easily create an insane on/off loop if the switches are actioned a couple of times too fast, I’m adding a bypass flow variable. But the thing is that I’m not being able to make the switch node react to the variable’s content.
[{"id":"fbb020a344ed4251","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"e161424c0c2c3e42","type":"server-state-changed","z":"fbb020a344ed4251","name":"switch.sonoff_10009bbf5d","server":"8a86b0cc.b2bac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.sonoff_10009bbf5d","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"bypassVar","propertyType":"msg","value":"laundryBypass","valueType":"str"},{"property":"otherDevice","propertyType":"msg","value":"input_boolean.laundry_light_test","valueType":"str"}],"x":150,"y":100,"wires":[["5012dc4cef66dc47"]]},{"id":"a0ff4820a55518c9","type":"server-state-changed","z":"fbb020a344ed4251","name":"input_boolean.laundry_light_test","server":"8a86b0cc.b2bac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.laundry_light_test","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"bypassVar","propertyType":"msg","value":"laundryBypass","valueType":"str"},{"property":"otherDevice","propertyType":"msg","value":"switch.sonoff_10009bbf5d","valueType":"str"}],"x":170,"y":160,"wires":[["5012dc4cef66dc47"]]},{"id":"1c866e9fe066e5bc","type":"change","z":"fbb020a344ed4251","name":"set bypass true","rules":[{"t":"set","p":"{{bypassVar}}","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":100,"wires":[["3c50890b26485123"]]},{"id":"5012dc4cef66dc47","type":"switch","z":"fbb020a344ed4251","name":"if bypass is false","property":"{{bypassVar}}","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":420,"y":100,"wires":[["1c866e9fe066e5bc","4bc88cbae40d8351"]]},{"id":"3c50890b26485123","type":"switch","z":"fbb020a344ed4251","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":750,"y":100,"wires":[["72e17a8ce1674c5f"],["09f09295b30a74b6"]]},{"id":"72e17a8ce1674c5f","type":"api-call-service","z":"fbb020a344ed4251","name":"","server":"8a86b0cc.b2bac","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{otherDevice}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":450,"y":180,"wires":[["8983ad9def963421","00c3f64cb0421198"]]},{"id":"09f09295b30a74b6","type":"api-call-service","z":"fbb020a344ed4251","name":"","server":"8a86b0cc.b2bac","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["{{otherDevice}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":450,"y":220,"wires":[["8983ad9def963421","00c3f64cb0421198"]]},{"id":"8983ad9def963421","type":"change","z":"fbb020a344ed4251","name":"set bypass false","rules":[{"t":"set","p":"{{bypassVar}}","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":200,"wires":[[]]},{"id":"00c3f64cb0421198","type":"debug","z":"fbb020a344ed4251","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":260,"wires":[]},{"id":"4bc88cbae40d8351","type":"debug","z":"fbb020a344ed4251","name":"debug 8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":40,"wires":[]},{"id":"8a86b0cc.b2bac","type":"server","name":"Home Assistant","version":4,"addon":true,"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":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]
Also, does every call service node need the Domain set up? If I’m just turning switches and lights on and off, what’s the use of indicating the domain?
What’s the best way to create a virtual switch for this purpose? I imagine I would need the virtual switch to have the same domain as the lights I want to control (I’m currently using an input boolean).
Feel free to give your suggestions, I’m interested in trying different ways of achieving this.
Thanks a lot,
Rodrigo