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.

REST API to KNX groups
#2
Try this:
Code:
date = os.date('%Y%m%d')

periodstart = date .. '0000'
periodend = date .. '2300'

url = 'https://web-api.tp.entsoe.eu/api?securityToken=XXXXXXXXXX&' ..
  'documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&' ..
  'periodStart=' .. periodstart .. '&periodEnd=' .. periodend

data, code = require('socket.http').request(url)
if not data or code ~= 200 then
  log('request failed', data, code)
  return
end

prices = {}
key = 0

callbacks = {
  StartElement = function(p, tag)
    if tag == 'TimeSeries' then
      key = key + 1
      prices[ key ] = {}
    elseif tag == 'position' then
      state = 'position'
    elseif tag == 'price.amount' then
      state = 'price'
    end
  end,
  EndElement = function(p, tag)
    state = nil
  end,
  CharacterData = function(p, value)
    value = value:trim()

    if #value > 0 then
      if state == 'position' then
        position = tonumber(value)
      elseif state == 'price' then
        prices[ key ][ position ] = tonumber(value)
      end
    end
  end
}

parser = require('lxp').new(callbacks)
parser:parse(data)
parser:close()

if key > 0 then
  rate = grp.getvalue('5/5/6')

  for i, price in pairs(prices[ 1 ]) do
    grp.checkupdate('1/1/' .. i, price * rate / 10)
  end
end
Reply


Messages In This Thread
REST API to KNX groups - by sx3 - 27.09.2022, 15:39
RE: REST API to KNX groups - by admin - 28.09.2022, 05:32
RE: REST API to KNX groups - by sx3 - 28.09.2022, 07:39
RE: REST API to KNX groups - by admin - 28.09.2022, 07:40
RE: REST API to KNX groups - by sx3 - 29.09.2022, 15:38
RE: REST API to KNX groups - by admin - 30.09.2022, 07:42

Forum Jump: