# Sonoff/Homekit/Dashboard switches synch'ing

**URL:** <https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990>\
**Category:** General\
**Created:** [10 May 2019 10:45 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990 "2019-05-10T10:45:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [10 May 2019 10:45 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990/1 "2019-05-10T10:45:39Z")

</div>

Hi all, first post so be nice 🙂

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.

 ![Sonoff%20Tasmota%20node%20red%20flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e33e010e09e01cb38089bbc5797efffa9c01e51e.png)

 ![Sonoff%20Tasmota%20nodes](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c0affdfff9fd08d514b39750e0aef523b59733c1.png)

```auto
[{"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!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 May 2019 12:49 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990/2 "2019-05-10T12:49:44Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [10 May 2019 19:47 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990/3 "2019-05-10T19:47:26Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 May 2019 20:19 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990/4 "2019-05-10T20:19:19Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [11 May 2019 07:28 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990/5 "2019-05-11T07:28:32Z")

</div>

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 😄

---

<div class="post-metadata">

**Author:** ![deon-dup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/deon-dup/32/13303_2.png) [@deon-dup](https://discourse.nodered.org/u/deon-dup)\
**Post date:** [18 October 2019 04:37 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990/6 "2019-10-18T04:37:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [18 October 2019 06:47 UTC](https://discourse.nodered.org/t/sonoff-homekit-dashboard-switches-synching/10990/7 "2019-10-18T06:47:19Z")

</div>

see the ReadMe for the node on [flows.nodered.org](http://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.
