Cayenne and Apple Homekit integration

About This Project

This project is about how to control the cayenne actuator widget from apple Homekit and to show cayenne sensor data on apple homekit.

What’s Connected

Any cayenne connected device which you want to access via homekit.
Raspberry Pi.

Procedure:
You need a node-red instance which you run locally on your raspberry pi.
Get the JWT access token by following this tutorial How to access Cayenne API using Insomnia, Node-red and Thunkable
Setup your apple homekit node. node-red-contrib-homekit-bridged - npm
Next import the following flow in your node-red:

[{"id":"38cd7623.8ce8ba","type":"debug","z":"fe62e480.655608","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":915,"y":280,"wires":[]},{"id":"879fe682.d88f08","type":"homekit-service","z":"fe62e480.655608","accessory":"c63d47f6.ef6678","name":"Ligth","serviceName":"Lightbulb","x":105,"y":316,"wires":[["741fb597.26d5bc"]]},{"id":"741fb597.26d5bc","type":"change","z":"fe62e480.655608","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.On","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":274.5,"y":315,"wires":[["10ce83c7.8c838c"]]},{"id":"10ce83c7.8c838c","type":"switch","z":"fe62e480.655608","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":319,"wires":[["8c5c8d9.20d3f7"],["c8291da0.7c8c5"]]},{"id":"8c5c8d9.20d3f7","type":"change","z":"fe62e480.655608","name":"Change payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":539,"y":269,"wires":[["a508c44c.2f41e8"]]},{"id":"c8291da0.7c8c5","type":"change","z":"fe62e480.655608","name":"Change payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":535.5,"y":361,"wires":[["79770fc5.47e1b"]]},{"id":"a508c44c.2f41e8","type":"function","z":"fe62e480.655608","name":"Set payload and Header","func":"var access = msg.payload;\nmsg.payload = {\n  \"channel\": \"5\",\n  \"value\": 1\n};\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Bearer accessToken';\nmsg.headers['Content-Type'] = 'application/json';\nreturn msg;","outputs":1,"noerr":0,"x":687.5,"y":204,"wires":[["3e1f2a6d.486a36"]]},{"id":"3e1f2a6d.486a36","type":"http request","z":"fe62e480.655608","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://platform.mydevices.com/v1.1/things/deviceID/cmd","tls":"","proxy":"","x":769.5,"y":279,"wires":[["38cd7623.8ce8ba"]]},{"id":"79770fc5.47e1b","type":"function","z":"fe62e480.655608","name":"Set payload and Header","func":"var access = msg.payload;\nmsg.payload = {\n  \"channel\": \"5\",\n  \"value\": 0\n};\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Bearer accessToken';\nmsg.headers['Content-Type'] = 'application/json';\nreturn msg;","outputs":1,"noerr":0,"x":763.5,"y":356,"wires":[["3e1f2a6d.486a36"]]},{"id":"92300fab.1de34","type":"function","z":"fe62e480.655608","name":"Set payload and Header","func":"var access = msg.payload;\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Bearer accessToken';\nreturn msg;","outputs":1,"noerr":0,"x":282.5,"y":512,"wires":[["2a0e6b83.682e64"]]},{"id":"2a0e6b83.682e64","type":"http request","z":"fe62e480.655608","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://platform.mydevices.com/v1.1/telemetry/deviceID/sensors/sensorID/summaries?type=latest","tls":"","proxy":"","x":496.5,"y":510,"wires":[["48c2ede2.b0e8c4","9f2b47b7.2eae08"]]},{"id":"48c2ede2.b0e8c4","type":"debug","z":"fe62e480.655608","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":724.5,"y":499,"wires":[]},{"id":"c8f64dd.7b182b","type":"inject","z":"fe62e480.655608","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"900","crontab":"","once":false,"onceDelay":"","x":105,"y":512,"wires":[["92300fab.1de34"]]},{"id":"9f2b47b7.2eae08","type":"json","z":"fe62e480.655608","name":"","property":"payload","action":"","pretty":false,"x":204.5,"y":622,"wires":[["abbccbb0.059518"]]},{"id":"e34f1ae1.f391d8","type":"debug","z":"fe62e480.655608","name":"","active":true,"console":false,"complete":"payload","x":780,"y":589,"wires":[]},{"id":"abbccbb0.059518","type":"change","z":"fe62e480.655608","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].v","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":432.5,"y":600,"wires":[["e34f1ae1.f391d8","26b6d034.b9388"]]},{"id":"94e5f3b8.97275","type":"homekit-service","z":"fe62e480.655608","accessory":"c63d47f6.ef6678","name":"","serviceName":"Thermostat","x":705,"y":688,"wires":[[]]},{"id":"26b6d034.b9388","type":"function","z":"fe62e480.655608","name":"convert_temp","func":"str=msg.payload;\nmsg.payload={\n    CurrentTemperature: parseFloat(str)\n}\nreturn msg;","outputs":1,"noerr":0,"x":455.5,"y":688,"wires":[["94e5f3b8.97275"]]},{"id":"c63d47f6.ef6678","type":"homekit-accessory","z":"","accessoryName":"cayenne-temp 2","pinCode":"111-11-111","port":"","manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","accessoryType":"7"}]

in this flow you need to edit the following:
Add the JWT access token in the 3 Change payload and header node.
Add the device ID and sensor ID in the URL of the HTTP request node.
if everything is correct you should get the following output in the debug.
Once you deploy the flow, you need to add this accessory on your apple home kit.

Photos of the Project

3 Likes