Created
August 4, 2020 15:26
-
-
Save MorningZ/4b75352b1c43a3e4c117d48285914337 to your computer and use it in GitHub Desktop.
Node-RED Flow for Hubitat Battery Levels and Temperatures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"8315935d.f4bf5","type":"tab","label":"Retrieve Attributes","disabled":false,"info":""},{"id":"f7bd1d06.ced7c","type":"http request","z":"8315935d.f4bf5","name":"Retrieve all given levels","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://HUBITAT-IP-ADDRESS/apps/api/MAKER-API-ID/devices/all?access_token=MAKER-API-TOKEN","tls":"","persist":false,"proxy":"","authType":"","x":810,"y":200,"wires":[["c2bfc020.0b7e8"]]},{"id":"8897885a.fd8598","type":"debug","z":"8315935d.f4bf5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1195,"y":200,"wires":[],"l":false},{"id":"704ee71f.e0b3e8","type":"inject","z":"8315935d.f4bf5","name":"Battery Levels","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"battery","x":570,"y":180,"wires":[["f7bd1d06.ced7c"]]},{"id":"c63b192a.511458","type":"inject","z":"8315935d.f4bf5","name":"Temperatures","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temperature","x":570,"y":220,"wires":[["f7bd1d06.ced7c"]]},{"id":"c2bfc020.0b7e8","type":"json","z":"8315935d.f4bf5","name":"Convert to object","property":"payload","action":"obj","pretty":false,"x":955,"y":200,"wires":[["1a83c87e.305e28"]],"l":false},{"id":"1a83c87e.305e28","type":"function","z":"8315935d.f4bf5","name":"Filter Devices","func":"\nlet matches = [];\n\nfor (let device of msg.payload) {\n switch(msg.topic) {\n case \"battery\": \n if (device.attributes && device.attributes.battery) {\n matches.push({ \"name\": device.label, \"type\": device.type, \"level\": parseInt(device.attributes.battery || 0.0) });\n }\n break;\n case \"temperature\":\n if (device.attributes && device.attributes.temperature) {\n matches.push({ \"name\": device.label, \"type\": device.type, \"level\": device.attributes.temperature });\n }\n break;\n }\n}\n\nreturn {\n \"topic\": msg.topic, \n \"payload\": matches\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1080,"y":200,"wires":[["8897885a.fd8598"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment