Hi @sach,
Thanks for your query.
I've created 2 bash scripts using the Hive v6 API:
1. hive2domo.sh - this gets the current and target heating temperatures from Hive, and sends these to dummy temperature devices in Domoticz; it also sends the current temperature as the setpoint to a dummy thermostat device. In addition, it sends the heating status (On / Off) to a dummy switch, by reading stateHeatingRelay in the API, so that I can see at a glance when the boiler is actually switched on for heating (I also graph all these variables using emoncms - see below).
To use this, you'll need to set up the following devices in Domoticz:
- dummy temperature device for current temperature
- dummy temperature device for target temperature
- dummy thermostat
- dummy switch for heating status
and find their idX values in the Settings > Devices tab of domoticz, and substitute their values for the <angle brackets> in the sketch below (e.g., replace <CURR TEMP> with 50). You'll also need to insert your Hive URL and password, again substituting the <angle brackets>.
I run this script every 5 minutes via crontab.
- Spoiler: show
Code: Select all
#!/bin/bash
# Sends current and target temperatures to Domoticz
cd "${0%/*}"
login=$(curl -s -k --cookie-jar cookie.jar -g -H "Content-Type: application/vnd.alertme.zoo-6.1+json" \
-H "Accept: application/vnd.alertme.zoo-6.2+json" -H "Content-Type: 'application/*+json'" \
-H "X-AlertMe-Client: Hive Web Dashboard" \
-d '{"sessions":[{"username":"<HIVE USERNAME>", "password":"<PASSWORD>"}]}' \
https://api.prod.bgchprod.info:443/omnia/auth/sessions)
sessionId=$(echo $login | python -c 'import sys, json; print json.load(sys.stdin)["sessions"][0]["sessionId"]')
nodes=$(curl -s -k --cookie-jar cookie.jar -g -H "Content-Type: application/vnd.alertme.zoo-6.2+json" \
-H "Accept: application/vnd.alertme.zoo-6.2+json" -H "Content-Type: 'application/*+json'" \
-H "X-AlertMe-Client: swagger" -H 'X-Omnia-Access-Token: '"$sessionId" \
https://api.prod.bgchprod.info:443/omnia/nodes)
temp1=$(echo $nodes | python -c 'import sys, json; print json.load(sys.stdin)["nodes"][2]["attributes"]["temperature"]["reportedValue"]')
printf -v temp "%.1f" "$temp1"
targetTemp=$(echo $nodes | python -c 'import sys, json; print json.load(sys.stdin)["nodes"][2]["attributes"]["targetHeatTemperature"]["reportedValue"]')
if [ $targetTemp = "1.0" ]; then
targetTemp="7.0"
fi
#echo $targetTemp
heating=$(echo $nodes | python -c 'import sys, json; print json.load(sys.stdin)["nodes"][2]["attributes"]["stateHeatingRelay"]["reportedValue"]')
if [ $heating = "ON" ]; then
heating="On"
elif [ $heating = "OFF" ]; then
heating="Off"
fi
domoTemp=$(curl -s "http://<DOMO URL>:<PORT>/json.htm?type=command¶m=udevice&nvalue=0&idx=<CURR TEMP>&svalue=${temp}")
domoSetPoint=$(curl -s "http://<DOMO URL>:<PORT>/json.htm?type=command¶m=udevice&nvalue=0&idx=<SETPOINT>&svalue=${temp}")
sleep 1
read old_target < target.txt
if [ $targetTemp != $old_target ]; then
domoTargetTemp=$(curl -s "http://<DOMO URL>:<PORT>/json.htm?type=command¶m=udevice&nvalue=0&idx=<TARGET>&svalue=${targetTemp}")
echo $targetTemp > target.txt
fi
sleep 1
read old_heating < heating.txt
#echo $old_heating, $heating
if [ $heating != $old_heating ]; then
domoHeating=$(curl -s "http://<DOMO URL>:<PORT>/json.htm?type=command¶m=switchlight&idx=<HEATING>&switchcmd=${heating}")
echo $heating > heating.txt
fi
logout=$(curl -s -k -X DELETE --cookie-jar cookie.jar -g -H "Content-Type: application/vnd.alertme.zoo-6.1+json" \
-H "Accept: application/vnd.alertme.zoo-6.2+json" -H "Content-Type: 'application/*+json'" \
-H "X-AlertMe-Client: Hive Web Dashboard" -H 'X-Omnia-Access-Token: '"$sessionId" \
"https://api.prod.bgchprod.info:443/omnia/auth/sessions/${sessionId}")
Emoncms graph example:
2. hive_boost.sh - this is a stand-alone script, which initiates a heating boost for a predetermined temperature (default: 22°C) and time (30 minutes) - these 2 parameters are held as user variables in Domoticz, and so can be changed there. To use, set up 2 user variables with the values you want in the Settings > User variables tab in Domoticz, and note their idX's, then replace <BOOST TEMP> and <BOOST TIME> in the script below.
To run, type ./hive_boost.sh from the directory where the script is stored (or you could store the script in one of the folders in your PATH, e.g., /usr/local/bin).
- Spoiler: show
Code: Select all
#!/bin/bash
# Hive Boost function (change duration and target temperature in boost curl)
login=$(curl -s -k --cookie-jar cookie.jar -g -H "Content-Type: application/vnd.alertme.zoo-6.1+json" \
-H "Accept: application/vnd.alertme.zoo-6.2+json" -H "Content-Type: 'application/*+json'" \
-H "X-AlertMe-Client: Hive Web Dashboard" \
-d '{"sessions":[{"username":"<HIVE URL>", "password":"<PASSWORD>"}]}' \
https://api.prod.bgchprod.info:443/omnia/auth/sessions)
sessionId=$(echo $login | python -c 'import sys, json; print json.load(sys.stdin)["sessions"][0]["sessionId"]')
nodes=$(curl -s -k --cookie-jar cookie.jar -g -H "Content-Type: application/vnd.alertme.zoo-6.2+json" \
-H "Accept: application/vnd.alertme.zoo-6.2+json" -H "Content-Type: 'application/*+json'" \
-H "X-AlertMe-Client: swagger" -H 'X-Omnia-Access-Token: '"$sessionId" \
https://api.prod.bgchprod.info:443/omnia/nodes)
nodeId=$(echo $nodes | python -c 'import sys, json; print json.load(sys.stdin)["nodes"][2]["id"]')
boost=$(curl -s -k "http://<DOMO URL>:<PORT>/json.htm?type=command¶m=getuservariable&idx=<BOOST TIME>")
boostTemp=$(echo $boost | python -c 'import sys, json; print json.load(sys.stdin)["result"][0]["Value"]')
boost=$(curl -s -k "http://<DOMO URL>:<PORT>/json.htm?type=command¶m=getuservariable&idx=<BOOST TEMP>")
boostTime=$(echo $boost | python -c 'import sys, json; print json.load(sys.stdin)["result"][0]["Value"]')
boost=$(curl -s -k --cookie-jar cookie.jar -X PUT -H "Content-Type: application/vnd.alertme.zoo-6.2+json" \
-H "Accept: application/vnd.alertme.zoo-6.2+json" -H "Content-Type: 'application/*+json'" \
-H "X-AlertMe-Client: swagger" -H 'X-Omnia-Access-Token: '"$sessionId" \
-d '{"nodes":[{"attributes":{"activeHeatCoolMode":{"targetValue":"BOOST"},"scheduleLockDuration":{"targetValue":"'"$boostTime"'"},"targetHeatTemperature":{"targetValue":"'"$boostTemp"'"}}}]}' \
"https://api.prod.bgchprod.info:443/omnia/nodes/${nodeId}")
logout=$(curl -s -k -X DELETE --cookie-jar cookie.jar -g -H "Content-Type: application/vnd.alertme.zoo-6.1+json" \
-H "Accept: application/vnd.alertme.zoo-6.2+json" -H "Content-Type: 'application/*+json'" \
-H "X-AlertMe-Client: Hive Web Dashboard" -H 'X-Omnia-Access-Token: '"$sessionId" \
"https://api.prod.bgchprod.info:443/omnia/auth/sessions/${sessionId}")
I'm sure there are better ways of writing these scripts, but they work for me! Good luck!