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
#5
Thanks Admin,

I went with the JSON API from Vattenfall instead, I have made the code to work. However not the prettiest code Big Grin
I would want that, if the Vattenfall homepage is not responding or something goes wrong fetching info, set all the group adresses to "0"
How should I think when writing that code!?


Also, the timestamp format is YYYY-MM--DD while the DTP 11 is DD-MM-YYYY, so the value in my groupadress is "00-00-2000" after writing.

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)

timestamp = data[1].TimeStampDay
    grp.checkupdate('5/5/28', timestamp)

price1 = data[1].Value
    grp.checkupdate('5/5/1', price1)

price2 = data[2].Value
    grp.checkupdate('5/5/2', price2)

price3 = data[3].Value
    grp.checkupdate('5/5/3', price3)

price4 = data[4].Value
    grp.checkupdate('5/5/4', price4)

price5 = data[5].Value
    grp.checkupdate('5/5/5', price5)

price6 = data[6].Value
    grp.checkupdate('5/5/6', price6)

price7 = data[7].Value
    grp.checkupdate('5/5/7', price7)

price8 = data[8].Value
    grp.checkupdate('5/5/8', price8)

price9 = data[9].Value
    grp.checkupdate('5/5/9', price9)

price10 = data[10].Value
    grp.checkupdate('5/5/10', price10)

price11 = data[11].Value
    grp.checkupdate('5/5/11', price11)

price12 = data[12].Value
    grp.checkupdate('5/5/12', price12)

price13 = data[13].Value
    grp.checkupdate('5/5/13', price13)

price14 = data[14].Value
    grp.checkupdate('5/5/14', price14)

price15 = data[15].Value
    grp.checkupdate('5/5/15', price15)

price16 = data[16].Value
    grp.checkupdate('5/5/16', price16)

price17 = data[17].Value
    grp.checkupdate('5/5/17', price17)

price18 = data[18].Value
    grp.checkupdate('5/5/18', price18)

price19 = data[19].Value
    grp.checkupdate('5/5/19', price19)

price20 = data[20].Value
    grp.checkupdate('5/5/20', price20)

price21 = data[21].Value
    grp.checkupdate('5/5/21', price21)

price22 = data[22].Value
    grp.checkupdate('5/5/22', price22)

price23 = data[23].Value
    grp.checkupdate('5/5/23', price23)

price24 = data[24].Value
    grp.checkupdate('5/5/24', price24)





medelpris = price1+price2+price3+price4+price5+price6+price7+price8+price9+price10+price11+price12+price13+price14+price15+price16+price17+price18+price19+price20+price21+price22+price23+price24
medelpris = medelpris / 24
    grp.checkupdate('5/5/25', medelpris)

maxpris = math.max(price1, price2, price3, price4, price5, price6, price7, price8, price9, price10, price11, price12, price13, price14, price15, price16, price17, price18, price19, price20, price21, price22, price23, price24)
    grp.checkupdate('5/5/26', maxpris)

minpris = math.min(price1, price2, price3, price4, price5, price6, price7, price8, price9, price10, price11, price12, price13, price14, price15, price16, price17, price18, price19, price20, price21, price22, price23, price24)
    grp.checkupdate('5/5/27', minpris)


log(price1,price2)
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: