Feeding Hive data to emoncms

Hi,

I have a BG Hive Heating system, and I have a Python script (courtesy of davetaz on http://britishgashive.freeforums.org/automated-json-feed-retrieval-t7-10...) which reads data from the Hive server and outputs it in JSON format to a daily file every 5 minutes (frequency is determined by cron, so can be made to run more often).

The feed consists of temperature data (inside, outside, target CH temperature), hot water schedule (on / off), and each entry is time-stamped.

I run this on my Mac, but as it's written in Python, it should also run on my Raspberry Pi which I use as my emonbase. I currently load each day's file (as a .csv) into Excel, and graph the above values.

Instead of writing data to a file, can the data be extracted as a live feed, and input to emoncms? If so, how?

Any help appreciated.

Mike

pb66's picture

Re: Feeding Hive data to emoncms

This shouldn't be too difficult to implement. Are you running emonHub on the Pi?

Paul

MikeF's picture

Re: Feeding Hive data to emoncms

Paul,

Yes.

Mike

[Multiple copies of several posts have been deleted. Please observe the message when your post is held for moderation and be patient. Moderator (RW)]

pb66's picture

Re: Feeding Hive data to emoncms

In-time a custom "hive" interfacer maybe possible but initially, I would recommend a little bridging script along similar lines to the script by davetaz and a couple of others I found. 

By using a socket interfacer emonhub can open a port and listen for incoming data, this is recently discussed in a thread about creating a custom script (for test purposes) which references an earlier thread on creating and using an EmonHubSocketInterfacer 

In emonhub.conf the [interfacers] section would require some settings like this added

[[Hive]]

    Type = EmonHubSocketInterfacer

    [[[init_settings]]]

        port_nb = 50013   # for example

    [[[runtimesettings]]] 

and then a python script running on the same Pi could fetch the data every n secs and forward it to port 50013.

The benefits of using a separate script are mainly to keep the experimental dev away from the main emonhub service (at least until it's stable) and currently emonhub's interfacers all run in the main thread which means if the hive interfacer was integral to emonhub and the network or hive site was down, emonhub would get bogged down waiting and retrying to contact hive rather than getting on with other stuff (like normal running) 

Can you post an example of your current csv output file? 

I do not have access to a hive account but If you are willing to be a guinea pig and test my attempts I can try and something together for you should you need it, even if it just gets you started.

Paul

MikeF's picture

Re: Feeding Hive data to emoncms

Thanks, Paul, I'll take a look at those threads.

I recently came across this thread: SOLVED: CurrentCost Monitor feed to EmonCMS, where the Perl script appears to be inserting data into a feed by using the following code:

my $emon_ua = LWP::UserAgent->new;
my $emon_url = "http://localhost/emoncms3/api/post?apikey=$key\&json={power:$watts,temp:$temp}";
my $emon_response = $emon_ua->get($emon_url);

Would this work (with the 2nd line suitably amended)?

I've attached a copy of a sample file (saved as xls, as csv attachments not allowed). Rows were added to this file by cron firing the python script every 30 minutes (this can obviously be done more frequently - every n secs). The columns I'm interested in are target, inside and outside (temperatures); you'll see there's other stuff which I'm not bothered with.

I'll be happy to test your attempts.

Mike

pb66's picture

Re: Feeding Hive data to emoncms

Sorry for a slow reply, I'm not familiar enough to comment on the code you quote and linked, but having seen the data (i assume the original file is just text csv, can the file be saved as .txt?)

The values should be easy(ish) to pick out and put into a string for a socket listener.

I will have a closer look over the next couple of days.

I have started a "emonhub modules "sandbox"" thread to pull together some ideas on this type of thing, that you might find useful

Paul.

MikeF's picture

Re: Feeding Hive data to emoncms

Hi Paul,

I've achieved what I wanted to, by following the emoncms API documentation.

I modified the python program that I identified in my original post
- I use the Hive JSON feeds to obtain the data I'm interested in: inside, outside and target (heating) temperatures
- instead of writing these to a file, I post them to emoncms.org using the csv format, as follows:

http://emoncms.org/input/post.json?node=10&apikey=XXXXXXXXXXXXXX&csv=18....

I now need to create feeds for these inputs, and set up a cron timer to run the python program every 60 secs.

I can post the python program if it would be useful to other people.

Thanks for your help.

Mike

MikeF's picture

Re: Feeding Hive data to emoncms

A bit more info on getting data from the Hive Active Heating system to emoncms:

There are a number of URLs available with Hive, which provide JSON feeds of heating and weather data. For example, this URL: https://my.hivehome.com/weather returns the following at my location:

{"inside":16.3,"outside":8,"weather":"cloudy_with_light_rain","city":"Princes Risborough","date":"19/02/15 11:07","datetime":"2015-02-19T11:07:08+0000"}

(You have to be authenticated first to do this). More information on the JSON feeds is here:

http://britishgashive.freeforums.org/automated-json-feed-retrieval-t7.html

I've taken the python program produced by davetaz from the above thread, and modified it so that instead of saving data to a file per day every 5 minutes, it posts the data to emoncms via the emoncms API. I'm sending inside, outside and target (heating) temperatures.

I've attached the python program and a JSON config file
- you need to enter your Hive username, password and emoncms API key in the config file
- and enter the path to the config file towards the beginning of the python program.

I've set up a cron job to run the python program every 60 seconds, and the data appears under node 10 on Inputs.

Please let me know if you have any queries with this.

Mike

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.