britishgashive.freeforums.org
http://britishgashive.freeforums.org/

Detecting heating on / off
http://britishgashive.freeforums.org/detecting-heating-on-off-t247.html
Page 1 of 1

Author:  mjf2708 [ Mon May 09, 2016 2:07 pm ]
Post subject:  Detecting heating on / off

Does anyone know if it's possible to detect Hive heating actually switching on / off (i.e., when the green light goes on / off on the receiver) through the API (v6)?

I'm graphing temperatures through Domoticz and emoncms. I've created a sensor which consists of a mains relay connected to the heating control wire in the connection box, with the relay contacts connected to a hacked LightwaveRF door sensor, which then sends an on / off signal to Domoticz whenever the heating switches on / off.

It would be good to be able to do this in the API (i.e., by software rather than hardware).

Author:  jamesleesaunders [ Sun Jun 19, 2016 1:47 pm ]
Post subject:  Re: Detecting heating on / off

Hi mjs2708,

Sure, couple of ways through the V6 API.

I have written a few useful API calls like the above on my website here:
http://www.smartofthehome.com/2016/05/hive-rest-api-v6/

You could call the 'nodes' API call to get the state of your thermostat (in particular looks for 'stateHeatingRelay'):

Quote:
https://api.prod.bgchprod.info:443/omnia/nodes/<<Id_of_your_receiver>>


{
  "meta": {},
  "links": {},
  "linked": {},
  "nodes": [
    {
      "id": "81414acc-9404-41fa-9947-c18990e7ed01",
      "href": "https://api.prod.bgchprod.info:8443/omnia/nodes/81414acc-9404-41fa-9947-c18990e7ed01",
      "links": {},
      "name": "Your Receiver",
      "nodeType": "http://alertme.com/schema/json/node.class.thermostat.json#",
      "parentNodeId": "2ba0f1e4-4f51-4aea-adb3-447908448786",
      "lastSeen": 1466343696284,
      "createdOn": 1452412238819,
      "userId": "cf82b9d8-8d0b-43b7-ae28-7a1fe907da52",
      "ownerId": "cf82b9d8-8d0b-43b7-ae28-7a1fe907da52",
      "attributes": {
        "supportsTransitionsPerDay": {
          "reportedValue": 6,
          "reportReceivedTime": 1466340569731
        },
        "holidayMode": {
          "reportedValue": {
            "targetHeatTemperature": 1
          },
          "reportReceivedTime": 1466340569731
        },
        "minHeatTemperature": {
          "reportedValue": 1,
          "reportReceivedTime": 1466340569731
        },
        "maxHeatTemperature": {
          "reportedValue": 32,
          "reportReceivedTime": 1466340569731
        },
        "temperature": {
          "reportedValue": 21.05,
          "reportReceivedTime": 1466343674003
        },
        "supportsHotWater": {
          "reportedValue": false,
          "reportReceivedTime": 1466340569731
        },
        "previousConfiguration": {
          "reportedValue": {
            "targetHeatTemperature": 16,
            "mode": "MANUAL"
          },
          "reportReceivedTime": 1466340569731
        },
        "frostProtectTemperature": {
          "reportedValue": 7,
          "reportReceivedTime": 1466343696284
        },
        "stateHeatingRelay": {
          "reportedValue": "OFF",
          "reportReceivedTime": 1466340569731
        },
        "activeOverrides": {
          "reportedValue": [],
          "reportReceivedTime": 1466340569731
        },
        "activeScheduleLock": {
          "reportedValue": true,
          "reportReceivedTime": 1466340569731
        },
        "activeHeatCoolMode": {
          "reportedValue": "HEAT",
          "reportReceivedTime": 1466340569731
        },
        "nodeType": {
          "reportedValue": "http://alertme.com/schema/json/node.class.thermostat.json#",
          "reportReceivedTime": 1466343696284
        },
        "targetHeatTemperature": {
          "reportedValue": 18.5,
          "targetValue": 18.5,
          "reportReceivedTime": 1466340569731,
          "targetSetTime": 1466098678522,
          "targetExpiryTime": 1466098978522,
          "targetSetTXId": "8c254ec0-ca51-4573-8cbc-bf2674f29e54",
          "propertyStatus": "COMPLETE"
        }
      }
    }
  ]
}


Or you could query the 'channels' API call to get historical heating relay (on/off) stats:

Quote:
https://api.prod.bgchprod.info:443/omnia/channels/controllerState@<<Id_of_your_receiver>>?start=1459357200000&end=1459360868000&rate=5&timeUnit=MINUTES&Operation=DATASET


{
  "meta": {},
  "links": {},
  "linked": {},
  "channels": [
    {
      "id": "[email protected]",
      "href": "https://api.prod.bgchprod.info:[email protected]8448786",
      "links": {
        "node": [
          "2ba0f1e4-4f51-4aea-adb3-447908448786"
        ]
      },
      "start": 1459357200000,
      "end": 1459360868000,
      "timeUnit": "MINUTES",
      "rate": 5,
      "unit": "ENCODED RELAY STATE",
      "values": {
        "1459357200000": 0,
        "1459357500000": 0,
        "1459357800000": 0,
        "1459358100000": 0,
        "1459358400000": 0,
        "1459358700000": 0,
        "1459359000000": 0,
        "1459359300000": 0,
        "1459359600000": 0,
        "1459359900000": 0,
        "1459360200000": 0,
        "1459360500000": 0
      },
      "operation": "DATASET"
    }
  ]
}


Jim

Author:  mjf2708 [ Sun Jun 19, 2016 9:40 pm ]
Post subject:  Re: Detecting heating on / off

Thanks, Jim, I tried the first of your approaches, and that works fine (hopefully, I won't need to monitor heating status at the moment - it is supposed to be summer!).

Thanks also for the link to Postman from your website - I'll be investigating that.

Mike

Author:  jamesleesaunders [ Wed Jun 22, 2016 9:11 pm ]
Post subject:  Re: Detecting heating on / off

Postman is a really cool!

Once installed you should then be able to add the following 'Collections' which I have setup for the Hive APIs into your Postman app:

* Hive API v5
https://www.getpostman.com/collections/ ... 3e7640b07e

* Hive API v6.1
https://www.getpostman.com/collections/ ... 59222e8b39

I have configured these to use session variables and it should populate variables such as hubId and sessionId automatically on login, but You may need to configure your own environment variables for:
"v6url" : "https://api.prod.bgchprod.info:443/omnia"
"v5url" : "https://api.bgchlivehome.co.uk/v5"
"username" : "[email protected]"
"password" : "pa$$word"

If you find these useful or have and additions or corrections please do share your ideas - I am happy to add further to these. I may pop them on GitHub to share.

Author:  w82 [ Sat Nov 26, 2016 1:16 pm ]
Post subject:  Re: Detecting heating on / off

Jim,

Your Postman collections are awesome - thanks for your work! And they work great. But I wondered if you could diagnose what I'm doing wrong in Python/Requests. The identical (I hope) headers and payload never lets me authenticate with v6.

Here's the collection code in Postman:

POST /omnia/auth/sessions HTTP/1.1
Host: api.prod.bgchprod.info:443
Content-Type: application/vnd.alertme.zoo-6.1+json
Accept: application/vnd.alertme.zoo-6.1+json
X-Omnia-Client: Hive Web Dashboard
Cache-Control: no-cache
Postman-Token: f64d9abf-e02d-9353-18df-71c26520bb0f

{
  "sessions": [{
    "username": "x",
    "password": "x",
    "caller": "WEB"
  }]
}


And Python:

import requests,json,sys
url="https://api.prod.bgchprod.info:443/omnia"
username='x'
password='x'

keys={"sessions": [{
    "username": username,
    "password": password,
    "caller": "WEB"
  }]
}

#keys = {'username':username,'password':password,'caller':'web'}
headers={'Content-Type':'application/vnd.alertme.zoo-6.1+json','Accept':'application/vnd.alertme.zoo-6.1+json', 'X-Omnia-Client':'Hive Web Dashboard'}


r = requests.post("https://api.prod.bgchprod.info:443/omnia/auth/sessions",params=keys,headers=headers,verify=False)
print r
print r.json()


I keep getting a 400 response, Json not readable, and so on. Both my headers and params seem correct - have tried everything I can think of! Any thoughts?

Thanks

Will

Author:  w82 [ Sun Nov 27, 2016 9:11 pm ]
Post subject:  Re: Detecting heating on / off

Sorted it. Put the payload (session/username params) in `json` in the python requests

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/