It is currently Mon May 29, 2017 9:02 pm



Welcome
Welcome to britishgashive

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!





 Page 7 of 8 [ 74 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next
Author Message
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Mon Mar 28, 2016 9:56 pm 

Joined: Sat Mar 26, 2016 6:47 pm
Posts: 7
Has thanked: 5 time
Have thanks: 0 time
I've been giving it a got for a couple of hours but I can't get the request correct.

I keep getting a bad request error when sending the JSON string with my username and password.

My request (raw format) looks like this:
Quote:
POST https://api.prod.bgchprod.info/omnia/auth/sessions HTTP/1.1
Content-Type: application/json
Accept: application/vnd.alertme.zoo-6.4+json
X-Alertme-Client: jlj
Host: api.prod.bgchprod.info
Content-Length: 79
Expect: 100-continue
Connection: Keep-Alive

{"sessions":[{"username":"xxxx%40xxxx.xxxx","password":"xxxxxxxx"}]}

and the response looks like this (raw format):
Quote:
HTTP/1.1 400 Bad Request
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Content-Type, X-Omnia-Client, X-AlertMe-Client, X-Omnia-Access-Token
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS
Cache-Control: no-cache
Cache-Control: no-store
Content-Type: application/vnd.alertme.zoo-6.4+json
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Pragma: no-cache
X-Zoo-Transaction-Id: c3fef796-cac1-471a-9baa-e3372be01203
Connection: keep-alive
Content-Length: 114

{"errors":[{"code":"USERNAME_PASSWORD_ERROR","title":"Username or password not specified or invalid","links":[]}]}


It all looks ok, although I get the same response if I use the "Try It Out!" option on https://api.prod.bgchprod.info/api/docs?docContext=v6&apiVersion=6.4#!/sessions/createSession_post_2

Can anyone see where the request error is?

Thanks,

Jason.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Tue Mar 29, 2016 6:25 am 

Joined: Fri Mar 18, 2016 7:10 pm
Posts: 20
Has thanked: 0 time
Have thanks: 4 time
Think you may be sending the wrong content type. Should be:

"Content-Type: application/vnd.alertme.zoo-6.2+json"
"Accept: application/vnd.alertme.zoo-6.2+json"

You are sending 'application/json' which will not work. Note both accept and content type need to be sent.

Also, I am not sure if it is mandatory but you don't appear to be sending 'caller' in your request data along with username and password (send 'WEB').

Jim


jamesleesaunders has been thanked by:
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Tue Mar 29, 2016 8:46 am 

Joined: Sat Mar 26, 2016 6:47 pm
Posts: 7
Has thanked: 5 time
Have thanks: 0 time
Jim,

many thanks for sticking with me on this. I just spent 20 minutes typing an overly comprehensive response with code examples, requests and responses all nicely quoted out. Then I checked I was using the correct API (as per your request header example above; which I wasn't) from the documentation site and thought I'd try one more time. It then struck me that I'd been encoding the username so that the "@" in my username was sent in html safe text and "%40". I changed this to simply send the "@", and what do know. It worked... :o :D :shock: :lol: :oops:

Thanks again and I'll post my progress here.

Jason.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Tue Mar 29, 2016 1:54 pm 

Joined: Sat Mar 26, 2016 6:47 pm
Posts: 7
Has thanked: 5 time
Have thanks: 0 time
Pretty well on top of it all now. I've got request and response classes built so my C# code is now code-safe and can utilise intelisense for all of the API members. I've got the following working :geek: :

Login
Get node ID
Get node[4] details including state of heating, temperature, etc.
Set temperature
Set and clear BOOST



I just need to see what else I can use from the JSON node object.

The weather info that was available in API V5 seems to have disappeared. Does any know if it's gone for good in API V6.x?

Thanks Jim for your pointers to get this stuff going.

J.


Attachments:
HiveScreenGrab.png
HiveScreenGrab.png [ 14.18 KiB | Viewed 605 times ]
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Fri Apr 01, 2016 11:56 am 

Joined: Thu Feb 19, 2015 10:52 am
Posts: 20
Has thanked: 1 time
Have thanks: 3 time
I've persevered with the v6 API, following dannydev's post (Nov 12 2015), and created a number of bash scripts using curl commands.

The first just logs in and displays the receiver node id. I've included echo statements, so that you can see the (complex!) JSON structure from each of the calls.

#!/bin/bash
# Hive login / display node details

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":"<HIVE PASSWORD>"}]}' \
   https://api.prod.bgchprod.info:443/omnia/auth/sessions)
   
echo $login | python -m json.tool

sessionId=$(echo $login | python -c 'import sys, json; print json.load(sys.stdin)["sessions"][0]["sessionId"]')
   
echo $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)
   
echo $nodes | python -m json.tool

nodeId=$(echo $nodes | python -c 'import sys, json; print json.load(sys.stdin)["nodes"][3]["id"]')

echo $nodeId

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}"


Just insert your Hive username and password in the first curl statement.

The next one sets the Boost function - it's currently fixed at 22C for 30 minutes (penultimate curl) - this script could be made interactive, to prompt for each of these values. (I needed to put the -d value all on one line - breaking it up didn't work.)

#!/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 USERNAME>", "password":"<HIVE 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"][3]["id"]')

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":30},"targetHeatTemperature":{"targetValue":22}}}]}' \
   "https://api.prod.bgchprod.info:443/omnia/nodes/${nodeId}")

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}"


Finally, I've created a script which sends heating current and target temperatures to Domoticz (the script is run by crontab every 5 minutes on my system). In this one, you'll need to insert your Domoticz URL and port, and the IDX's of 2 temperature devices which you'll need to set up (this assumes you are familiar with Domoticz and creating devices).

#!/bin/bash
# Sends current and target temperatures to Domoticz

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":"<HIVE 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"][3]["id"]')

temp1=$(echo $nodes | python -c 'import sys, json; print json.load(sys.stdin)["nodes"][2]["attributes"]["temperature"]["reportedValue"]')
temp=$(echo "$temp1" | sed -re 's/([0-9]+\.[0-9]{1})[0-9]+/\1/g')

targetTemp=$(echo $nodes | python -c 'import sys, json; print json.load(sys.stdin)["nodes"][2]["attributes"]["targetHeatTemperature"]["reportedValue"]')

domoTemp=$(curl -s "http://<DOMO URL>:<DOMO PORT>/json.htm?type=command&param=udevice&nvalue=0&idx=<TEMP IDX>&svalue=${temp}")
domoTargetTemp=$(curl -s "http://<DOMO URL>:<DOMO PORT>/json.htm?type=command&param=udevice&nvalue=0&idx=<TARGET IDX>&svalue=${targetTemp}")

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}"


There are other Hive functions which could be controlled in the same way, and I'll post any further scripts I create. I found Firefox's 'Inspect Element > Network Monitor' to be invaluable here, in decoding the API.

Hope this is useful!

Mike


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Fri Apr 01, 2016 12:15 pm 

Joined: Thu Feb 19, 2015 10:52 am
Posts: 20
Has thanked: 1 time
Have thanks: 3 time
jamesjl said:
Quote:
The weather info that was available in API V5 seems to have disappeared. Does any know if it's gone for good in API V6.x?

There's an API call as follows (my postcode):
https://weather-prod.bgchprod.info/weather?postcode=HP279AY

which returns the following JSON:
{
    "weather":
{
    "icon": "day_black_low_cloud",
    "description": "Overcast ",
    "temperature":
        {
            "unit": "C",
            "value": ​8.0
        }
    }
}

As in my previous post, I found this by using Firefox's 'Inspect Element > Network Monitor' function (I've not created a curl statement for this).


mjf2708 has been thanked by:
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Thu Jun 16, 2016 6:53 pm 

Joined: Fri Mar 18, 2016 7:10 pm
Posts: 20
Has thanked: 0 time
Have thanks: 4 time
To anyone who is interested I have written a new post about Hives v6.2 API here:

http://www.smartofthehome.com/2016/05/hive-rest-api-v6/

Please feel free to comment / suggest improvements.

Jim


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Jul 17, 2016 9:11 pm 

Joined: Thu Feb 19, 2015 10:52 am
Posts: 20
Has thanked: 1 time
Have thanks: 3 time
I use emoncms to graph Hive temperatures via Domoticz (I'm using the v6 API).

One of the values I'm graphing is targetHeatTemperature. When heating is set to Schedule, this picks up the value as shown in the webpage / app (e.g., 20.0C). However, when heating is set to Off, the JSON returns 1, whereas the webpage / app shows the frost protect temperature, i.e., 7C. Also, when in holiday mode, the JSON returns 7.

Is there any way to get a consistent value?


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Jul 17, 2016 10:01 pm 

Joined: Thu Mar 06, 2014 1:15 am
Posts: 10
Has thanked: 0 time
Have thanks: 1 time
I would assume anything equal to or less than 7 is in frost protection mode which is 7 degrees.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Mon Jul 18, 2016 7:57 am 

Joined: Thu Feb 19, 2015 10:52 am
Posts: 20
Has thanked: 1 time
Have thanks: 3 time
Agreed (and I've modified my python script accordingly) - it's just that I was looking for a consistent behaviour in the API.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 7 of 8 [ 74 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

cron

suspicion-preferred