Hi all
I am very new to node red and home automation. I have a switch at the bottom of the stairs and one also at the top. There is also a lamp at top and bottom of stairs, ie. hall/landing.
I have been trying to create a setup whereby when one of the switches is turned on, both lamps come on and the other switch changes to match the state. Also, If one of the lamps is turned on from HomeKit or home assistant, switches should mirror this..
I have managed to achieve what I wanted to do, apart from once it is triggered, a loop begins and switches and lamps rapidly cycle on/off.
I know I am doing something stupid, but being new to it, I cannot see where.
Could anybody please look at this and point me in the right direction?
[
{
"id": "13a1a7ceb6a497a4",
"type": "group",
"z": "2a17042efaa3b23d",
"style": {
"stroke": "#999999",
"stroke-opacity": "1",
"fill": "none",
"fill-opacity": "1",
"label": true,
"label-position": "nw",
"color": "#a4a4a4"
},
"nodes": [
"7ff3a66a.bd9c08",
"52e0bc3b.617904",
"acbfa624.3650d8",
"bb484857.94bc",
"a0834568.7e447",
"406daced.472844",
"a33d117e.961728",
"d2d365921bab591a",
"e29e54f8eb805979"
],
"x": 54,
"y": 139,
"w": 972,
"h": 242
},
{
"id": "7ff3a66a.bd9c08",
"type": "mqtt in",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"topic": "zigbee2mqtt/Stairs Switch/state_l1",
"qos": "2",
"datatype": "auto-detect",
"broker": "12dd1610.da9e4a",
"nl": false,
"rap": false,
"rh": "0",
"inputs": 0,
"x": 220,
"y": 220,
"wires": [
[
"bb484857.94bc"
]
]
},
{
"id": "52e0bc3b.617904",
"type": "mqtt in",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"topic": "zigbee2mqtt/Landing Switch/state_l3",
"qos": "2",
"datatype": "auto-detect",
"broker": "12dd1610.da9e4a",
"nl": false,
"rap": false,
"rh": "0",
"inputs": 0,
"x": 230,
"y": 280,
"wires": [
[]
]
},
{
"id": "acbfa624.3650d8",
"type": "mqtt out",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"topic": "zigbee2mqtt/Stairs Switch/l1/set",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "12dd1610.da9e4a",
"x": 850,
"y": 340,
"wires": []
},
{
"id": "bb484857.94bc",
"type": "function",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "2way stairs lights",
"func": "var newMsg = { topic: \"zigbee2mqtt/Stairs Switch/state_l1\"}; \nvar hallstairs=flow.get('hallstairs') || 0;\nvar newMsg = { topic: \"zigbee2mqtt/Landing Switch/state_l3\" };\nvar landingstairs = flow.get('landingstairs') || 0;\nvar newMsg = { topic: \"zigbee2mqtt/Stairs/state\" };\nvar stairs = flow.get('stairs') || 0;\n\n//if (msg.topic===\"\"zigbee2mqtt/Landing Switch/state_l3\") {\nif (landingstairs === 0) {\n if (msg.payload === \"ON\") {\n newMsg.payload = \"ON\";\n landingstairs = 1\n flow.set('landingstairs', landingstairs);\n return newMsg;\n }\n}\nelse {\n if (msg.payload === \"OFF\") {\n newMsg.payload = \"OFF\";\n landingstairs = 0;\n flow.set('landingstairs', landingstairs);\n return newMsg;\n }\n}\n//if (msg.topic===\"zigbee2mqtt/Stairs Switch/state_l1\") {\nif (hallstairs === 0) {\n if (msg.payload === \"ON\") {\n newMsg.payload = \"ON\";\n hallstairs = 1\n flow.set('hallstairs', hallstairs);\n return newMsg;\n }\n}\nelse {\n if (msg.payload === \"OFF\") {\n newMsg.payload = \"OFF\";\n hallstairs = 0;\n flow.set('hallstairs', hallstairs);\n return newMsg;\n }\n}\n//if (msg.topic===\"zigbee2mqtt/Stairs/state\") {\nif (stairs === 0) {\n if (msg.payload === \"ON\") {\n newMsg.payload = \"ON\";\n stairs = 1\n flow.set('stairs', stairs);\n return newMsg;\n }\n}\nelse {\n if (msg.payload === \"OFF\") {\n newMsg.payload = \"OFF\";\n stairs = 0;\n flow.set('stairs', stairs);\n return newMsg;\n }\n}\n//}",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 510,
"y": 320,
"wires": [
[
"a0834568.7e447",
"d2d365921bab591a",
"acbfa624.3650d8"
],
[]
],
"inputLabels": [
"House/LightLobbyA/stat/POWER"
]
},
{
"id": "a0834568.7e447",
"type": "mqtt out",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"topic": "zigbee2mqtt/Stairs/set",
"qos": "",
"retain": "false",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "12dd1610.da9e4a",
"x": 820,
"y": 220,
"wires": []
},
{
"id": "406daced.472844",
"type": "inject",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"props": [
{
"p": "payload",
"v": "ON",
"vt": "str"
},
{
"p": "topic",
"v": "",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "ON",
"payloadType": "str",
"x": 550,
"y": 180,
"wires": [
[
"bb484857.94bc"
]
],
"outputLabels": [
"House/LightLobbyA/stat/POWER"
]
},
{
"id": "a33d117e.961728",
"type": "inject",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"props": [
{
"p": "payload",
"v": "OFF",
"vt": "str"
},
{
"p": "topic",
"v": "",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "OFF",
"payloadType": "str",
"x": 550,
"y": 220,
"wires": [
[
"bb484857.94bc"
]
],
"outputLabels": [
"House/LightLobbyA/stat/POWER"
]
},
{
"id": "d2d365921bab591a",
"type": "mqtt out",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"topic": "zigbee2mqtt/Landing Switch/l3/set",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "1071c397f831a1ed",
"x": 860,
"y": 280,
"wires": []
},
{
"id": "e29e54f8eb805979",
"type": "mqtt in",
"z": "2a17042efaa3b23d",
"g": "13a1a7ceb6a497a4",
"name": "",
"topic": "zigbee2mqtt/Stairs/state",
"qos": "2",
"datatype": "auto-detect",
"broker": "1071c397f831a1ed",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 190,
"y": 340,
"wires": [
[
"bb484857.94bc"
]
]
},
{
"id": "12dd1610.da9e4a",
"type": "mqtt-broker",
"name": "",
"broker": "localhost",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "1071c397f831a1ed",
"type": "mqtt-broker",
"name": "",
"broker": "localhost",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]