17.11.2022, 06:42
Check this script out that Admin helped me out with a couple of days/weeks ago. It fetches the prices from Vattenfall API, maybe it will work for you with your price area?
In my Case I live in Sweden, pricearea SN3 (SE3).
Easiest practise would be to find a API with JSON output I beleive.
In my Case I live in Sweden, pricearea SN3 (SE3).
Easiest practise would be to find a API with JSON output I beleive.
Code:
require('json')
https = require 'ssl.https'
date = os.date('%Y-%m-%d')
url = 'https://www.vattenfall.se/api/price/spot/pricearea/' .. date .. '/' .. date .. '/SN3'
status = ssl.https.request(url)
data = json.decode(status)
if type(data) ~= 'table' then
return
end
ts = data[ 1 ].TimeStampDay
if type(ts) == 'string' then
ts = ts:split('-')
grp.checkupdate('5/5/28', {
year = tonumber(ts[1]),
month = tonumber(ts[2]),
day = tonumber(ts[3])
})
end
min = math.huge
max = -math.huge
cnt = 0
sum = 0
for i, item in ipairs(data) do
price = item.Value
min = math.min(min, price)
max = math.max(max, price)
sum = sum + price
cnt = cnt + 1
grp.checkupdate('5/5/' .. i, price)
end
grp.checkupdate('5/5/25', sum / cnt)
grp.checkupdate('5/5/26', max)
grp.checkupdate('5/5/27', min)