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.

Get prices from webpage via Excel
#10
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.


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.
Reply


Messages In This Thread
Get prices from webpage via Excel - by Rune - 02.05.2018, 18:57
RE: Get prices from webpage via Excel - by Jørn - 09.05.2018, 16:23

Forum Jump: