This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Reading Data from awattar API
#1
Hello everybody,
there is a new electricity provider in Austria and Germany that offers electricity prices at market prices.
I would like to read the hourly electricity prices for the next 24 hours via a script. The prices for the next 24 hours should be visible in a table and a group address should be addressed in the hour with the cheapest electricity.


Here is the description of the provider:

API - PRICE DATA FEED
Become an energy pioneer with our API data feed and realize your own ideas
Whether it's a heat pump, e-car or your battery: your devices automatically know when it's green and cheap via the aWATTar data interface. And the day before. The aWATTar electricity price interface allows inventors and developers to develop their own ideas for the energy transition and lower prices. Access is free for all aWATTar customers.

What data does the data feed provide?
Our data feed provides the exchange prices for the next day via a defined web interface. These are the data of the EPEX Spot electricity exchange, which are updated every day at 2:00 p.m. for the next day.

What do I need to use?
Become an aWATTar customer and use our data feed free of charge according to the fair use principle (60 queries per minute). You currently do not need an access token!

wb_sunny
Intelligent
Automatic shift of your electricity consumption

all_inclusive
Innovative
Fully automated and without loss of comfort

star
Optimized price
Consume when it's cheap

check
Forward-looking
For a green and sustainable future

DOCUMENTATION
Basics
server

https://api.awattar.de

resource

v1 / marketdata

call

HTTP GET

Encryption

SSL - HTTPS

Data format

JSON

parameter
begin
Epoch seconds including milliseconds. Defines the start time from which the data should be retrieved. (Optional)

end
Epoch seconds including milliseconds. Defines the end time up to which the data should be retrieved. (Optional)

RESPONSE
example

{
  "object": "list",
  "data": [{

    // Value for money in Epoch milliseconds
    "start_timestamp": 1428591600000,

     // Value for money up to in Epoch milliseconds
    "end_timestamp": 1428595200000,

    // Market price in euros / MWh, excluding VAT.
    "market price": 42.09,

    "unit": "Eur / MWh"},
    ...
  ]
}
TOKEN
No access token is currently required.

EXAMPLE
$ curl https://api.awattar.de/v1/marketdata
Delivers the electricity price data from now up to 24 hours into the future.

$ curl "https://api.awattar.de/v1/marketdata?start=1565481600000"
Returns the electricity prices from August 11, 2019 8:00 a.m. - August 12, 2019 8:00 a.m. (24 hours).

$ curl "https://api.awattar.de/v1/marketdata?start=1565481600000&end=1565665200000"
Returns the electricity prices from August 11, 2019 8:00 a.m. to August 13, 2019 3:00 a.m.



source: https://www.awattar.de/services/api

I would be happy if someone already has a ready solution for me.
best regards
Benjamin

Reply
#2
Hi,

Try this:
Code:
-- Load needed libs
require("ssl.https")
require('json')

-- Fetch data from API
data, code = ssl.https.request('https://api.awattar.de/v1/marketdata')

-- Check if data is received and decode JSON to LUA table
if data then
  tabledata = json.pdecode(data)
else
  -- No data recieved, exit script
  return
end

-- Check if decoded data is available
if tabledata then
  if type(tabledata.data) == 'table' then
    cheapest = tabledata.data[1].marketprice
    cheapestindex = 1
    -- Iterate tabledata to find the cheapest hour
    for key, value in pairs(tabledata.data) do
      -- find cheapest hour
      if value.marketprice < cheapest then
        cheapest = value.marketprice
        cheapestindex = key
      end
      -- Create & Add timestamps in human readable format
      tabledata.data[key].start_timestamp_hr = os.date('%A %d %B %H:%M',math.floor(tabledata.data[cheapestindex].start_timestamp/1000 + 0.5))
      tabledata.data[key].end_timestamp_hr = os.date('%A %d %B %H:%M',math.floor(tabledata.data[cheapestindex].end_timestamp/1000 + 0.5))
    end
   
    -- Log received table
    log(tabledata.data)
   
    -- Cheapest hour
    log(tabledata.data[cheapestindex])
   
    -- Write hour to KNX object as byte value
    grp.checkwrite('1/1/1', os.date('*t', math.floor(tabledata.data[cheapestindex].start_timestamp/1000 + 0.5)).hour)
   
  end
end
BR,

Erwin
Reply


Forum Jump: