Sonoff/Homekit/Dashboard switches synch'ing

Hi all, first post so be nice :slight_smile:

I've been using node red a few weeks, and have little knowledge of JSON at present. From the posts I have been reading I may be out of my depth!

Could I get your thoughts on this flow, it works fine but is it good practice? i.e. is there a more simple solution I am missing?

There is a dashboard switch, a Homekit switch on iPhone, and the physical switch on the Sonoff (Tasmota firmware). Pressing any button toggles the Sonoff output, and dresses the other switches.

[{"id":"346c0959.7434e6","type":"homekit-service","z":"fa1345d7.0957a8","isParent":true,"bridge":"9679c348.3a24a","parentService":"","name":"(Homekit) Left kitchen under cupboard","serviceName":"Switch","topic":"","filter":false,"manufacturer":"null","model":"null","serialNo":"null","characteristicProperties":"","x":270,"y":260,"wires":[["f91b44aa.3134a8","79335d6b.951a54"]],"inputLabels":["input"]},{"id":"f91b44aa.3134a8","type":"ui_switch","z":"fa1345d7.0957a8","name":"(Dashboard) Left kitchen under cupboard","label":"Left kitchen under cupboard","tooltip":"","group":"6b06c45.47e7a3c","order":2,"width":0,"height":0,"passthru":false,"topic":"","style":"","onvalue":"{\"On\":true}","onvalueType":"json","onicon":"","oncolor":"","offvalue":"{\"On\":false}","offvalueType":"json","officon":"","offcolor":"","x":300,"y":140,"wires":[["346c0959.7434e6"]]},{"id":"145f29b3.3ba656","type":"mqtt out","z":"fa1345d7.0957a8","name":"MQTT out: Sonoff cmnd/DVES_8C4BF7_fb/power","topic":"cmnd/DVES_8C4BF7_fb/power","qos":"","retain":"","broker":"5615eece.b3a81","x":930,"y":260,"wires":[]},{"id":"d8eb346b.857468","type":"debug","z":"fa1345d7.0957a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":160,"wires":[]},{"id":"79335d6b.951a54","type":"function","z":"fa1345d7.0957a8","name":"func","func":"node.status({fill:\"red\",shape:\"ring\",text:msg.payload.On});\nreturn { payload: msg.payload.On };","outputs":1,"noerr":0,"x":550,"y":260,"wires":[["145f29b3.3ba656","d8eb346b.857468"]]},{"id":"b419a87a.442098","type":"mqtt in","z":"fa1345d7.0957a8","name":"stat/DVES_8C4BF7_fb/POWER","topic":"stat/DVES_8C4BF7_fb/POWER","qos":"1","datatype":"auto","broker":"5615eece.b3a81","x":230,"y":420,"wires":[["ca6e3a08.cfa0a8"]]},{"id":"ca6e3a08.cfa0a8","type":"change","z":"fa1345d7.0957a8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"{\"On\":true}","tot":"json"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"{\"On\":false}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":420,"wires":[["346c0959.7434e6","ab407683.9e3fd8"]]},{"id":"ab407683.9e3fd8","type":"debug","z":"fa1345d7.0957a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":440,"wires":[]},{"id":"9679c348.3a24a","type":"homekit-bridge","z":"","bridgeName":"Virtual Bridge","pinCode":"111-11-111","port":"","allowInsecureRequest":false,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true},{"id":"6b06c45.47e7a3c","type":"ui_group","z":"","name":"Lights","tab":"a9f8fa81.8f0588","order":1,"disp":true,"width":"6","collapse":false},{"id":"5615eece.b3a81","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.95","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"a9f8fa81.8f0588","type":"ui_tab","z":"","name":"Kitchen","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Thanks for any pointers!

As long as you don't see any loops and it is working, it looks fine.
I realised myself that a dashboard switch, while having homekit on both mac/iphone/ipad would be a little redudant :wink:

Hi @bakman2 there aren't loops, all is good. I don't really understand the functions though, I googled and read but don't get it - yet.

  1. It seems the homekit node needs an 'object' called "{"On":true}" or {"On":false}.

  2. The Sonoff seems to need a boolean true of false to operate.

  3. The function has the code "return { payload: msg.payload.On };"

I can't see how that changes the payload from a JSON object to a boolean true/false. I might be totally misunderstanding it.

I'm still deciding what to use for my main display, I have a spare iPad mini 4 which I was thinking of using. I'm torn between dashboard, homekit or Blynk...

The homekit node produces {msg.payload.On} (true/false), in your function node, you are "reading" the value of msg.payload.On and sending it to mqtt, this is the hint: you don't need the function node, just connect the homekit node to mqtt directly. (if the sonoff accepts true/false)

1 Like

I will check that, thanks for the explanation. I think it didn’t work first time without the function node, but there is a bug with HomeKit-bridged where node red needs restarting before the HomeKit node will work correctly. So it might have been that.

Ta :smile:

Hi, I'm quite new to Homekit on Node Red. I'm trying to use the Homekit node (not the Bridge), with a Sonoff-Basic and MQTT into the Homekit node. The Sonoff provides 0/1, and I used the Change node as above to change to true/false. I don't however understand the required format. After numerous attempts, I get a range of messages ranging from "payload does not expect a Boolean", "integer", "string", etc. What exactly should the input be for STATE into the node?

see the ReadMe for the node on flows.nodered.org. which contains the general format, and a suggestion as how to check the specific format for the hardware type you are using. Generally they expect msg.payload to be an object.