Skip to content

Instantly share code, notes, and snippets.

@twonk

twonk/README.md Secret

Last active May 22, 2020 08:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twonk/62e04c333b192f6119d9d5b72f675d5f to your computer and use it in GitHub Desktop.
Save twonk/62e04c333b192f6119d9d5b72f675d5f to your computer and use it in GitHub Desktop.
Hive Hot Water boost control example.

A sample flow to control a Hive Thermostats hot water boost function.
The flow logs into the Hive website. Retrieves a list of nodes, finds the Hot Water Relay, and sets it in boost mode for 30 minutes.

Nodes to edit:

"Turn On" change the msg.action amount to be the number of minutes to run the boost

"Set Username and Password" Enter your hive website username and password

"Set Twitter Name" and "Tweet" Either remove these, or enter your details if you want to be notified that the flow was unable to login to Hive.

I use this with HA-Bridge / Domoticz / MQTT / Alexa to control my hot water at home.
With Alexa, I can say "Alexa, turn on the hot water" and she will run this flow (changing the start node to http inputs and calling from HA-Bridge). The native Alexa hive skill is more clunky, requiring "Alexa, tell hive to boost my hot water", and this always results in a 1 hour boost, which is too much.

[{"id":"5839ae0e.452f5","type":"http request","z":"e5a8dfd7.979f9","name":"Login to Hive","method":"POST","ret":"obj","url":"https://api-prod.bgchprod.info/omnia/auth/sessions","x":470,"y":220,"wires":[["594f91a4.a0ee9"]]},{"id":"809c9c17.bc751","type":"function","z":"e5a8dfd7.979f9","name":"Set Username and Password","func":"\nmsg.headers = {\n 'Content-Type' : 'application/vnd.alertme.zoo-6.1+json',\n 'Accept' : 'application/vnd.alertme.zoo-6.1+json',\n 'X-Omnia-Client' : 'Hive Web Dashboard'\n};\nmsg.payload = JSON.stringify({\n sessions: [\n { username: \"EnterYourHiveUserIDHere\",\n password: \"EnterYourHivePasswordHere\",\n caller: \"WEB\" \n }\n ] \n }\n)\n\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":120,"wires":[["5839ae0e.452f5"]]},{"id":"b0d60cf1.8e60e","type":"inject","z":"e5a8dfd7.979f9","name":"start","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":70,"y":80,"wires":[["6b7b6780.885978"]]},{"id":"47cadd4.87e7c24","type":"function","z":"e5a8dfd7.979f9","name":"set Hive request headers","func":"if(msg.payload.sessions !== undefined){\n\n //save the session out to the msg so we can use it later on\n msg.this_session = msg.payload.sessions[0].id;\n\n msg.headers = {\n 'Content-Type' : 'application/vnd.alertme.zoo-6.1+json',\n 'Accept' : 'application/vnd.alertme.zoo-6.1+json',\n 'X-Omnia-Client' : 'Hive Web Dashboard',\n 'X-Omnia-Access-Token' : msg.this_session\n }\n return msg;\n}\n\nreturn null;","outputs":1,"noerr":0,"x":304,"y":289,"wires":[["c7941f64.4624e"]]},{"id":"c7941f64.4624e","type":"http request","z":"e5a8dfd7.979f9","name":"Get nodes from Hive","method":"GET","ret":"obj","url":"https://api-prod.bgchprod.info/omnia/nodes","tls":"","x":572,"y":289,"wires":[["dee54cb9.c29e8"]]},{"id":"dee54cb9.c29e8","type":"function","z":"e5a8dfd7.979f9","name":"Set Hot Water Boost","func":"\nvar hwnode = {};\n\nif(msg.payload.nodes !== undefined){\n \n var nodes = msg.payload.nodes;\n \n for (var n in nodes){\n \n var attribs = nodes[n].attributes;\n \n if(nodes[n].name==\"Receiver\"){\n if(attribs.stateHotWaterRelay !== undefined){\n hwnode = nodes[n];\n }\n }\n } \n}\n\nmsg.headers = {\n 'Content-Type' : 'application/vnd.alertme.zoo-6.1+json',\n 'Accept' : 'application/vnd.alertme.zoo-6.1+json',\n 'X-Omnia-Client' : 'Hive Web Dashboard',\n 'X-Omnia-Access-Token' : msg.this_session\n}\nmsg.url = \"https://api-prod.bgchprod.info/omnia/nodes/\"+hwnode.id;\nif (msg.action>0){\n msg.payload =\n { nodes:[{\n attributes : {\n activeHeatCoolMode: {targetValue:\"BOOST\"},\n scheduleLockDuration : {targetValue: msg.action}\n }\n }]\n };\n}else{\n msg.payload =\n { nodes:[{\n attributes : {\n activeHeatCoolMode: {targetValue:\"HEAT\"},\n activeScheduleLock : {targetValue: false}\n }\n }]\n };\n}\n\nreturn msg;\n\n","outputs":"1","noerr":0,"x":293,"y":376,"wires":[["22a00ef6.0a1722"]]},{"id":"5dcd6366.e89c7c","type":"function","z":"e5a8dfd7.979f9","name":"set Headers & URL for Logout","func":"msg.headers = {\n 'Content-Type' : 'application/vnd.alertme.zoo-6.1+json',\n 'Accept' : 'application/vnd.alertme.zoo-6.1+json',\n 'X-Omnia-Client' : 'Hive Web Dashboard',\n 'X-Omnia-Access-Token' : msg.this_session\n}\nmsg.url = \"https://api-prod.bgchprod.info/omnia/auth/sessions/\"+msg.this_session\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":460,"wires":[["4bfb765c.f96cd8"]]},{"id":"4bfb765c.f96cd8","type":"http request","z":"e5a8dfd7.979f9","name":"logout from Hive","method":"DELETE","ret":"txt","url":"","tls":"","x":580,"y":460,"wires":[[]]},{"id":"594f91a4.a0ee9","type":"switch","z":"e5a8dfd7.979f9","name":"Logged In?","property":"statusCode","rules":[{"t":"neq","v":"200"},{"t":"eq","v":"200"}],"checkall":"true","outputs":2,"x":649,"y":219,"wires":[["2d68f050.f355"],["47cadd4.87e7c24"]]},{"id":"e41d7b0d.7fd448","type":"twitter out","z":"e5a8dfd7.979f9","twitter":"","name":"Tweet","x":970,"y":160,"wires":[]},{"id":"2d68f050.f355","type":"function","z":"e5a8dfd7.979f9","name":"Set Twitter Name","func":"msg.payload = \"D YourTwitterName unable to login to hive status code \"+msg.statusCode;\nreturn msg;","outputs":1,"noerr":0,"x":810,"y":160,"wires":[["e41d7b0d.7fd448"]]},{"id":"22a00ef6.0a1722","type":"http request","z":"e5a8dfd7.979f9","name":"Send Hot Water Boost","method":"PUT","ret":"obj","url":"","tls":"","x":561,"y":378,"wires":[["5dcd6366.e89c7c"]]},{"id":"6b7b6780.885978","type":"function","z":"e5a8dfd7.979f9","name":"Turn On","func":"//set the number of minutes that we want the HW boost to \n//be active for. Set to 0 to turn off (see Turn Off node)\nmsg.action = 30;\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":80,"wires":[["809c9c17.bc751"]]},{"id":"7c89c8c5.0c5d08","type":"inject","z":"e5a8dfd7.979f9","name":"start","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":70,"y":160,"wires":[["21b09c74.0102b4"]]},{"id":"21b09c74.0102b4","type":"function","z":"e5a8dfd7.979f9","name":"Turn Off","func":"//set the msg.action to zero to turn off the HW boost\nmsg.action = 0;\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":160,"wires":[["809c9c17.bc751"]]},{"id":"7e807621.28c428","type":"comment","z":"e5a8dfd7.979f9","name":"Edit this node","info":"adding your own Hive website username and password","x":470,"y":80,"wires":[]},{"id":"f52799b7.d68fb8","type":"comment","z":"e5a8dfd7.979f9","name":"Edit these node, or remove them","info":"Either remove these nodes if you dont want to\ntweet a failed login, or add your twitter \ncredentials and set the message text ","x":870,"y":120,"wires":[]}]
@PedanticPete
Copy link

See that you are not active at present but thanks for this, it gave me an 'in' to getting some data off my Hive hub ... why to BG make it so hard ...

@twonk
Copy link
Author

twonk commented May 22, 2020

@PedanticPete

See that you are not active at present but thanks for this, it gave me an 'in' to getting some data off my Hive hub ... why to BG make it so hard ...

Glad this was useful! I had to change my thermostat a couple of months back - it was drainging batteries faster than I could buy new ones. Had to make a couple of modifications to the flow as it looked like the responses had changed a little bit - nothing major, but thats the fun of working with an unpublished API 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment