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.

Power price API -> grp. adresses on Wiser
#7
Thanks alot! Big Grin 

I've ended up with this, and it seems to be working. I have tried to make the script move the values over to the storage, once a day, to visualise the right cost at the right time Smile 
Dont mind the danish text at the right side, im just trying to make my way through the code Tongue 
Code:
url = 'https://api.energidataservice.dk/dataset/Elspotprices?offset=0&filter=%7B%22PriceArea%22:%22dk1%22%7D&sort=HourDK%20DESC&timezone=dk&limit=24'

resp = require('ssl.https').request(url)
data = require('json').decode(resp).records

max = 0                                                                                                                                                     --nulstiller max værdi
min = math.huge                                                                                                                                     --nulstiller min værdi med uendeligt stort tal
sum = 0                                                                                                                                                        --nulstiller sum værdi


                                                                                  --Skriver time:minutter i "tid".

                                                                                  -- %a    abbreviated weekday name (e.g., Wed)
                                                                                  -- %A    full weekday name (e.g., Wednesday)
                                                                                  -- %b    abbreviated month name (e.g., Sep)
                                                                                  -- %B    full month name (e.g., September)
                                                                                  -- %c    date and time (e.g., 09/16/98 23:48:10)
                                                                                  -- %d    day of the month (16) [01-31]
                                                                                  -- %H    hour, using a 24-hour clock (23) [00-23]
                                                                                  -- %I    hour, using a 12-hour clock (11) [01-12]
                                                                                  -- %M    minute (48) [00-59]
                                                                                  -- %m    month (09) [01-12]
                                                                                  -- %p    either "am" or "pm" (pm)
                                                                                  -- %S    second (10) [00-61]
                                                                                  -- %w    weekday (3) [0-6 = Sunday-Saturday]
                                                                                  -- %x    date (e.g., 09/16/98)
                                                                                  -- %X    time (e.g., 23:48:10)
                                                                                  -- %Y    full year (1998)
                                                                                  -- %y    two-digit year (98) [00-99]
                                                                                  -- %%    the character `%´


tidtimer = os.date("%H")
tidminutter = os.date("%M")

for i, item in ipairs(data) do
  price = item.SpotPriceDKK/1000                                                                                                     --tildeler ordet price værdien af feltet SpotPriceDKK og deler med 1000 for at gå fra GW til KW.

  max = math.max(max, price)
  min = math.min(min, price)
  sum = sum + price

  grp.checkupdate('13/4/' ..i, price)
  item.hour = tonumber(item.HourDK:match('T(%d+)'))
 
                                                                                                                                                                    --Gemmer prisen fra igår i datalager under Spotpris1...23
 
if tidtimer == 12 and tidminutter == 00 then
  storage.set('Spotpris' ..i, price)
    end
end

avg = sum / #data

grp.checkupdate('13/4/25', avg)
grp.checkupdate('13/4/26', max)
grp.checkupdate('13/4/27', min)

table.sort(data, function(a, b)
  return a.SpotPriceDKK < b.SpotPriceDKK
end)

list = {}

for i = 1, 4 do
  item = data[ i ]
  list[ #list + 1 ] = string.format('%d = %.2f', item.hour, item.SpotPriceDKK)
end

hours = table.concat(list, '; ')
grp.checkupdate('13/4/28', hours)


                                                                                                                                                                    -- viser angivede enheder i loggen
log(avg, max, min, tidtimer, tidminutter, hours)
Reply


Messages In This Thread
RE: Power price API -> grp. adresses on Wiser - by ClausP - 10.11.2022, 15:11

Forum Jump: