Getting kwh used today

Is there a way I could get kwh used today in a way you get feeds (feed api)?

TrystanLea's picture

Re: Getting kwh used today

Hello SimonK, You can get a single kWh reading that covers any period with cumulative kWh feeds by making two api requests - its a bit complicated but very possible. One for the latest value with /feed/value.json?id=FEEDID and another using the data request api for example to get the value at the start of today (1st of april):

/feed/data.json?id=FEEDID&start=1459465200000&end=1459465201000&interval=1

the timestamps need to be in milliseconds and the end time 1s after the start time with interval set to 1.

myelectric does this internally for last week, month, year totals here: https://github.com/emoncms/app/blob/9.0/myelectric/myelectric.js#L425

 

TrystanLea's picture

Re: Getting kwh used today

A little bit more by way of example, using data from home:

https://emoncms.org/feed/data.json?id=116693&start=1459465200000&end=145...
returns: [[1459465200000,152.37690734863],[1459465210000,152.37690734863]]
the first value is the value that matches the request timestamp we want.
 

https://emoncms.org/feed/value.json?id=116693
returns: "154.33682027241"

154.33682027241 - 152.37690734863 = 1.96 kWh today (solar not very sunny)

 

SimonK's picture

Re: Getting kwh used today

Thank you!

This is what I get for the last day (not today) ie. for yesterday.

{"success":false,"message":"request datapoint limit reached (3000), increase request interval or time range, requested datapoints = 82799"}
 

SimonK's picture

Re: Getting kwh used today

It looks like I have too many data points (every 10s)

TrystanLea's picture

Re: Getting kwh used today

I think your start and end timestamps are too far apart. They need to be 1 second apart:

https://emoncms.org/feed/data.json?id=116693&start=1459465200000&end=1459465201000&interval=1

Timestamps in milliseconds:

1459465200000
1459465201000 (1 second difference)

Comment viewing options

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