Community
OpenEnergyMonitor

Community

Data feed from API

Hello guys,

Thanks a lot for this incredible tool !

Everything works well ! There is just a part of the API ( data.json) that I do not understand.
My goal here is to get 2 values of a feed (at different unixtime) and calculate its difference.
I thought data.json ( https://emoncms.org/feed/data.json?id=0&start=UNIXTIME_MILLISECONDS&end=UNIXTIME_MILLISECONDS&interval=10) could help me but it is not working exactly how I thought.

First question : is it possible to get one feed value at a specific unixtime ? (Maybe without data.json)

Here is the challenge : you have this kind of cumulative value on your feed (virtual values and dates):
Unixtime : value
1 : 0
2 : 0
5 : 0
6 : 2
7 : 3
8 : 3
20 : 3
21 : 4
22 : 4
50 : 4

Imagine, you would like to have the value difference between unixtime 4 and unixtime 23 (answer is 4 because unixtime 5 : 0 and unixtime 22 : 4 )
With available API how would you do ?

Wish you the best and thank you again for this crazy good software !

Hello @Boubou

We do a similar thing in some of the emoncms apps using the feed/data api e.g https://github.com/emoncms/app/blob/master/Lib/feed.js#L172

Set the start time to the time you wish to request and the end time to 1 second later than the start time. Set the interval to 1s. The result is usually two datapoints, with the first one being the correct one to use.

https://emoncms.org/feed/data.json?id=0&start=UNIXTIME_MILLISECONDS&end=UNIXTIME_MILLISECONDS+1000&interval=1