It is currently Fri Jul 21, 2017 12:40 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 1 of 8 [ 74 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next
Author Message
 Post subject: Automated JSON Feed retrieval
PostPosted: Mon Oct 28, 2013 9:45 pm 
Site Admin

Joined: Thu Oct 24, 2013 11:28 am
Posts: 80
Has thanked: 1 time
Have thanks: 7 time
For those of you with a linux interest, I've been hacking with a little "curl" script this evening to extract the temperature stats from the hive website:

#!/bin/bash

cookie_jar=hive_cookie.tmp
web_page=hive.tmp
username=<enter your hive username here, normally email address>
password=<password>

curl --cookie-jar $cookie_jar \
        --output ${web_page}_1 \
        https://www.hivehome.com/


curl --cookie $cookie_jar --cookie-jar $cookie_jar \
        --location \
        --data "username=${username}&password=${password}" \
        --output ${web_page}_2 \
        https://www.hivehome.com/login

curl --silent --cookie $cookie_jar --cookie-jar $cookie_jar \
        --location \
        --output ${web_page}_today \
        https://www.hivehome.com/myhive/history/today

curl --silent --cookie $cookie_jar --cookie-jar $cookie_jar \
        --location \
        --output ${web_page}_logout \
        https://www.hivehome.com/logout


Let me know how you get on with this, I've had to tailor it from the script I'm using as I have a lot more automated logging on my setup, but I'd be interested to see how useful this is for anyone interested.

As you can see you should be able to modify the elements as you see fit, but if its runs okay you should have a few files in /tmp specifically hive.tmp_today which will contain along with headers the json feed for your temperatures today.



_________________
Installation Type: Hive Active Heating
Installation Date: 25/10/2013
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Mon Oct 28, 2013 10:53 pm 
Site Admin

Joined: Thu Oct 24, 2013 11:28 am
Posts: 80
Has thanked: 1 time
Have thanks: 7 time
Quick update on this one, it appears if you add a header to the request then you can force json output on pretty much all feeds:

curl "${SILENT}" --silent --cookie $cookie_jar --cookie-jar $cookie_jar \
        --location \
        --output ${web_page}_schedule \
        --header "X-Requested-With: XmlHttpRequest" \
        https://www.hivehome.com/myhive/hotwater/schedule


Works really well, I've only tested the hotwater schedule, but can only assume the others will have similar success.

Think I'm already getting to the stage where I can start to prototype a new Android client with a slightly better schedule display. (Personal preference, but just appears a bit clunky to me)

Any other Android, IOS developers out there interested in a collaboration with a github source repository?



_________________
Installation Type: Hive Active Heating
Installation Date: 25/10/2013
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Tue Oct 29, 2013 8:18 pm 
Site Admin

Joined: Thu Oct 24, 2013 11:28 am
Posts: 80
Has thanked: 1 time
Have thanks: 7 time
Few more updates on some interesting things I've found whilst playing:

Simplified status information. I've found an easier way to authenticate to the hive system:

curl --cookie-jar cookie.jar -X POST -H "Content-Type: application/json" -d '{"username":"<YOUR HIVE EMAIL>","password":"<YOUR HIVE PASSWORD>"}' https://www.hivehome.com/login


The "--cookie-jar cookie.jar" element of the command allows any cookies which are set by the command to be stored in a local file (cookie.jar) e.g. Authentication cookies

The cookie can then be used in subsequent calls to authenticate the request and allow access to your hive data

Therefore, subsequent calls use "--cookie cookie.jar" so that the cookie is available if the application requests it. We also add the original "--cookie-jar cookie.jar" in case any new cookies are set as part of the new call.

So once we are "logged in" with the above call, we can get todays temperature history simply by running:

curl --cookie cookie.jar --cookie-jar cookie.jar https://www.hivehome.com/myhive/history/today


this basic command works fine with the temperature history, however, if you want to use the more comprehensive feeds you will need to add the "--header "X-Requested-With: XmlHttpRequest" header which will ensure only the json feed is returned.

curl --cookie cookie.jar --cookie-jar cookie.jar --header "X-Requested-With: XmlHttpRequest" https://www.hivehome.com/myhive/heating/target


I've also managed to work out how to set the heating temperature as follows:
curl --cookie cookie.jar --cookie-jar cookie.jar -X PUT -d id=1 -d target=20 https://www.hivehome.com/myhive/heating/target


This will set your heating temperature to the "target" temperature e.g. 20 degrees C in this case.

Oh yes, before I forget, don't forget to clean up behind you and log yourself out once you are done

curl --cookie cookie.jar --cookie-jar cookie.jar https://www.hivehome.com/logout


Unfortunately, or fortunately, I'm off to Las Vegas for 5 days so will have to put any further updates on hold, however, I'll be looking at the Android development aspects when I return and I'll post some code samples to aid any would-be developers to get off the mark.



_________________
Installation Type: Hive Active Heating
Installation Date: 25/10/2013
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Tue Dec 03, 2013 8:04 am 

Joined: Tue Dec 03, 2013 7:26 am
Posts: 10
Has thanked: 2 time
Have thanks: 2 time
Thanks - very useful info. If we can set the temperature directly, then wouldn't this allow us to have our own local control system, so that e.g. we can have more than the the 4 events?


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Tue Dec 03, 2013 12:29 pm 
Site Admin

Joined: Thu Oct 24, 2013 11:28 am
Posts: 80
Has thanked: 1 time
Have thanks: 7 time
Yes, there is that functionality. I'm currently using a Raspberry PI for this as I've got a quirky issue where my 22:30 temperature reduction to 4.5degrees is sometimes missed and the heating then stays on all night.

I have a cronjob set to 23:00 which after login runs:

curl --cookie cookie.jar --cookie-jar cookie.jar -X PUT -d id=1 -d target=4.5 https://www.hivehome.com/myhive/heating/target


to ensure the heating is turned off. This could be expanded to replace the BG scheduling altogether if you wanted.



_________________
Installation Type: Hive Active Heating
Installation Date: 25/10/2013
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Tue Dec 03, 2013 10:46 pm 

Joined: Tue Dec 03, 2013 7:26 am
Posts: 10
Has thanked: 2 time
Have thanks: 2 time
I also set up a cron job on an ubuntu server I have running here to give me an extra on/off session during the day, as well as storing hourly logs of the temperature etc, so that I can review later.

In the future, it may be interesting to see how the internal temperature builds up as a function of external temperature. We can then have profiles that kick in depending on external temperature thresholds.

Quick question though - do you know if it is possible to tell the actual state of the boiler (i.e. if it is on/off), other than just assuming if the room temp is less than the target then boiler is on etc?

Thanks again.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Wed Dec 04, 2013 7:51 am 
Site Admin

Joined: Thu Oct 24, 2013 11:28 am
Posts: 80
Has thanked: 1 time
Have thanks: 7 time
Sounds like we have a similar setup. I'm storing similar info:

DATE,TIME,TARGET,CURRENT,OUTSIDE
04/12/13,05:00,21.5,18.7,7.2
04/12/13,05:30,21.5,19,7.2
04/12/13,06:00,21.5,19.4,7.8
04/12/13,06:30,21.5,19.9,7.8
04/12/13,07:00,21.5,20.2,7.2
04/12/13,07:30,21.5,20.7,7.2


and you have the same thoughts as me. I want to know how fast the house heats up when the outside temp is say 0 against how long when outside temp is 10. This may give some properties on how efficient the house is at retaining heat. This will also show on the rate of decrease when the heating is off.

The 2 URL's you need for the info you requested are:

https://www.hivehome.com/myhive/heating/target
{"target":4.5}

https://www.hivehome.com/myhive/weather
{"inside":20,"outside":2.8,"weather":"light_rain_showers","city":"Childwall"}


I don't currently know of a way to check if the boiler is on or off, however, as part of the widget I've basically assumed:

target temp < current temp = boiler ON


Hope this helps.



_________________
Installation Type: Hive Active Heating
Installation Date: 25/10/2013
bazza2000 has been thanked by:
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Thu Dec 05, 2013 7:11 am 

Joined: Tue Dec 03, 2013 7:26 am
Posts: 10
Has thanked: 2 time
Have thanks: 2 time
Thanks for the above, and yes those are the urls I'm using to grab the temperatures. I'll be looking into this as time permits.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Thu Dec 12, 2013 8:18 am 

Joined: Tue Dec 03, 2013 7:26 am
Posts: 10
Has thanked: 2 time
Have thanks: 2 time
In case anyone wants an easier way schedule additional events, gcalcron2 takes entries from a Google Calendar and can execute shell tasks as cron jobs. https://github.com/fabriceb/GCalCron2


smar has been thanked by:
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Thu Dec 12, 2013 12:29 pm 
Site Admin

Joined: Thu Oct 24, 2013 11:28 am
Posts: 80
Has thanked: 1 time
Have thanks: 7 time
Like the looks of this, will get it installed and see how it goes.



_________________
Installation Type: Hive Active Heating
Installation Date: 25/10/2013
Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 8 [ 74 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next


Who is online

Users browsing this forum: No registered users and 0 guests


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