I’m running Hassio from the official image on a Raspberry Pi and Node-Red for my automations.
So this is what you can do if you have a similar setup:
- Enable ffmpeg in HA like this: https://www.home-assistant.io/integrations/ffmpeg/#configuration
- Add this to the config
camera:
- platform: ffmpeg
input: !include nanitinput.yaml
name: Nanit
- Import this into Node-Red. This flow will retrieve baby_uid and accesstoken automatically every 2 hours and build the corresponding feed URL which will be written into a file called nanitinput.yaml, which is what the config file reads.
[{"id":"95617a57.280438","type":"inject","z":"c35e4544.aab968","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"7200","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":720,"wires":[[]]},{"id":"a83d0bad.d2ae48","type":"http request","z":"c35e4544.aab968","name":"POST","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.nanit.com/login","tls":"","persist":false,"proxy":"","authType":"","x":410,"y":720,"wires":[["a61e3ce5.84f8e"]]},{"id":"7cb6d684.58bd18","type":"function","z":"c35e4544.aab968","name":"","func":"msg.payload = { \n \"email\" :\"XXXXX\",\n \"password\" :\"XXXXX\"\n}\nmsg.headers = {};\nmsg.headers['x-tc-transform'] = 'tti-app';\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['x-tc-transformVersion'] = '0.2';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":720,"wires":[["a83d0bad.d2ae48"]]},{"id":"a61e3ce5.84f8e","type":"json","z":"c35e4544.aab968","name":"","property":"payload","action":"","pretty":false,"x":530,"y":720,"wires":[["c887b424.95deb8"]]},{"id":"c887b424.95deb8","type":"change","z":"c35e4544.aab968","name":"Filter token","rules":[{"t":"set","p":"nanittoken","pt":"flow","to":"payload.access_token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":720,"wires":[["fcb222c3.0bf"]]},{"id":"557ade78.7148b","type":"file","z":"c35e4544.aab968","name":"Write to nanitinput.yaml","filename":"/config/nanitinput.yaml","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":1690,"y":720,"wires":[[]]},{"id":"57b64395.3f180c","type":"function","z":"c35e4544.aab968","name":"Construct Feed URL","func":"msg.payload = \"-i rtmps://media-secured.nanit.com/nanit/\"+ flow.get(\"nanitbabyuid\") +\".\" + flow.get(\"nanittoken\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1460,"y":720,"wires":[["557ade78.7148b"]]},{"id":"66828159.0a098","type":"http request","z":"c35e4544.aab968","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://api.nanit.com/babies","tls":"","persist":false,"proxy":"","authType":"","x":970,"y":720,"wires":[["c3b81b67.b9b618"]]},{"id":"fcb222c3.0bf","type":"function","z":"c35e4544.aab968","name":"","func":"msg.headers = {};\nmsg.headers['x-tc-transform'] = 'tti-app';\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['x-tc-transformVersion'] = '0.2';\nmsg.headers['Authorization'] = 'Token ' + flow.get(\"nanittoken\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":820,"y":720,"wires":[["66828159.0a098"]]},{"id":"c3b81b67.b9b618","type":"json","z":"c35e4544.aab968","name":"","property":"payload","action":"","pretty":false,"x":1110,"y":720,"wires":[["f23be6d0.b6a698"]]},{"id":"f23be6d0.b6a698","type":"change","z":"c35e4544.aab968","name":"Filter babyuid","rules":[{"t":"set","p":"nanitbabyuid","pt":"flow","to":"payload.babies.uid","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":720,"wires":[["57b64395.3f180c"]]}]
- Make sure to replace both XXXXX with your username and password in the first function node
Since I haven’t been using this for too long, I’m not sure if refreshing the token every 2 hours is too little or too much. But this can be changed later at the bottom of the inject node.
EDIT: Not working as expected. Requires a restart of Hassio in order to detect changes to the token.