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.

Script with Dutch power prices
#6
Hello,
I'm trying to create a script to retrieve tomorrow's electricity prices with api: https://www.hvakosterstrommen.no/strompris-api.

I try this:
Code:
local http = require('ssl.https') local json = require('json') local date = os.date('*t', os.time() + 86400) -- get tomorrow's date local year = tostring(date.year) local month = string.format('%02d', date.month) local day = string.format('%02d', date.day) local area = 'NO1' -- specify area local url = string.format('https://www.hvakosterstrommen.no/api/v1/prices/%s/%s-%s_%s.json', year, month, day, area) print('Fetching data from URL:', url) local body, code, headers, status = http.request(url) print('HTTP response code:', code) if code == 200 then     print('Data retrieved successfully')     print('Response body:', body)     local data = json.decode(body)     local group_address = '32/1/%d' -- starting group address     for i, item in ipairs(data) do         local hour = tonumber(string.sub(item.time_start, 12, 13))         local price = item.NOK_per_kWh         print('Hour:', hour)         print('Price:', price)         if price ~= nil then             local value = string.format('%014s', string.format('%.4f', price * 10000)):gsub(' ', '0')             print('Value:', value)             grp.write(string.format(group_address, hour), value, '14ByteAsc')         end     end else     print('Error fetching data: ' .. status) end

I'm having a bit of trouble getting the data out.
Reply


Messages In This Thread
RE: Script with Dutch power prices - by admin - 30.05.2022, 10:34
RE: Script with Dutch power prices - by admin - 31.05.2022, 08:52
RE: Script with Dutch power prices - by JASK - 15.03.2023, 21:20
RE: Script with Dutch power prices - by admin - 16.03.2023, 06:25

Forum Jump: