09.05.2018, 16:23
Allright, cleaned that up and added some other (i think) useful functions (:
Also put all configurable parameters easily available at the top of the script.
Also put all configurable parameters easily available at the top of the script.
Code:
output = '1/1/1' -- output group address, 14 byte
city = 1 -- 1 = Oslo, 2 = Kr.sand, 3 = Bergen, 4 = Tr.heim, 5 = Molde, 6 = Tromsø
timeshift = 1 -- 0= Last hour, 1 = current hour, 2 = next hour
scale = 1 -- 1 = MWh price, 1000 = KWh price.
-- Script for writing hourly power prices from nordpool to knx object.
require('json')
require('ssl.https')
now = os.date('*t')
pickhour = now.hour + timeshift
param = os.date('%d-%m-%Y', os.time(date))
res = ssl.https.request('https://www.nordpoolgroup.com/api/marketdata/page/23?currency=NOK&endDate=' .. param)
values = {}
if res then
res = json.pdecode(res)
if type(res) == 'table' then
for _, row in ipairs(res.data.Rows) do
cols = row.Columns
value = cols[ city ].Value:gsub(',', '.')
values[ #values + 1 ] = tonumber(value)
end
end
end
grp.write(output, values[pickhour] / scale)
Best regards, Jørn.