Retrieve data from local emoncms


I’m trying to retrieve data from some feeds of my local emoncms. I’ll use this data in a python script afterwards.

I’m trying to do it using information from Is this still valid? I get no results, using, for example:

wget -qO- "$APIKEY"

(I have my read api key stored at the $APIKEY variable).

In particular, I need the last month data (from day 1 of the month to the actual moment) from some feeds.

Thanks a lot

I just so happen to be working on a similar thing on a local Emoncms Version 10.2.6
I am working on a CRON job to retrieve data and put in a file.
I had to add Authorization: Bearer before the API key to get it to read.
Maybe you have a similar problem?


#Enter the API Keys here

#Set the Feed IDs here

#Fetch the data from the feeds on the emonpi

PI_IMPORT=$(curl -s$PI_IMPORT_FEED_ID -H “Authorization: Bearer LOCAL_RO_KEY”)

echo “–”
echo “This is the raw data…”
echo $PI_IMPORT >> file.txt

Hi @dlmpryor.

Thanks for your answer!!

I have tried your script (I have an emoncms 10.2.6 too), and I get a route not found error.

PI_IMPORT={"success":false,"message":"406 Not Acceptable. Route not found"}

Do you mean local “on the same machine” or “on the same LAN” to the device you are issuing the api call?

This is pointing at, not your local emoncms. You need to swap out the “” to your local emoncms IP or hostname.

Buhay’s suggestion is pointing at the local, as in the “same machine” since it uses the IP (aka “this same” host as the api call is issued from) so if your local emoncms is on another device on your LAN you would again need to replace “” with the IP or hostname of your local emoncms device.

Always try your api calls from a browser to test if https://IP.OF.MY.EMONCMS/feed/value.json?id=7&apikey=APIKEY works from a LAN connected browser, it should work fine in your script.

Like Paul said use your browser. Following is my results:
Read API Key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Using Chrome -H “Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”

Using Firefox -H “Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”

success false
message “406 Not Acceptable. Route not found”

I mean “the same machine”. I point to

Yes, sorry. Bad example. I’d been trying both pointing to my loopback address and to

Ok, calling it from my browser it works fine (using http in spite of https). Thanks! I’ll investigate why it didn’t work before.

Yes, I get the same message.

How can I transform:
To get the last month data, from day 1 to today? I suppose I’ll need to calculate the milliseconds from this date, and use something like this:

Thanks a lot, I have been trying it for a lot of hours and I really appreciate some help.


Here some links to example scripts.
They may or may not help.
I referenced them because I am thinking about using scripting to send a email alert when Input Threshold is Reached.

Thanks @dlmpryor and @pb66 , this last example (wathdog script) helps me to learn how to work with different time values.

Now I’m able to retrieve the last feed value, but I still have problems when I try to recover the old ones. For example, if I call:

I get:

That contains the correct time values, but the feed data is always a null value.

Hello @poldom a good way of working out the correct API request is to first open the feed using the emoncms graph interface and then open your browsers Developer Tools > Network tab to see the requests made to create the graph.

You may need to click the ‘Reload’ button on the graph interface to see the first request:

1 Like

Thanks @TrystanLea, it works!

Finally, after a lot of hours trying it, I have a new world of experiments to try.

One last question. Is it possible to generate a new feed, similar to the “use_kwh” one, but containing the data from a range of hours (for example, the energy used from 12:00 to 14:00)? Or it will be easier to retrieve this data from the general “use_kwh” feed?

Hello @poldom, the emoncms time of use app uses an API that I realise is not documented that may help with what you want to do. Again if you use the browser network tab you can see how it works.

The steps to load the time of use app are: Navigate to Apps, create new (+ New) then select the time of use app. Select a consumption feed and a cumulative kWh feed.

Note the paramaters in the /feed/data requests made.


The result gives the cumulative kWh value at midnight, 1am and 7am for each day. You can then work out what the consumption between 7am and 1am is by subtracting those values.

Thanks @TrystanLea, the split option is exactly what I was looking for. I had tried the “time of use” app, but I never looked at the network tab.

Well, now I have sufficent tools for my project. If I’m able to develop it I’ll post it here, maybe it can be useful for others.

Thanks again, I’m always proud of my emonpi, It’s a kind of proof of what open software & hardware can do.

1 Like

One last question. Is it possible to ask the database for the value of a feed at a specific time?

I had been looking for it at Emoncms - site api but I have only found how to retrieve the last data, or the data between an interval.

Hello @poldom

You can do this with the /feed/data/ api, its a bit convoluted but it does work:

Set the start time to the timestamp that you wish to request in milliseconds and the end time to 1s later. Set the interval to 1.


The result will be two values:


the first value is the value corresponding to the requested time.

To make this a bit easier I’ve just pushed a new api to the emoncms master branch for use initially on local emoncms installations. The api is:


the result gives the value only.

Thanks @TrystanLea, I’ll try to download the changes from github , and if I cannot do it I’ll use the other solution.

I’m really pleasantly surprised by the speed in developing code of this project…

1 Like