Hello people!
Im all new to all this scripting thing with my Wiser.
I have been looking at the forum, and found an other script that more or less say it does what I want.
Then i've changed some of the parameters and the API.
When I run the script i just get this awnswer in the alert log:
Resident script:12: attempt to index a nil value
stack traceback:
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
Dont mind the danish text at the right side, im just trying to make my way through the 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).recordsmax = 0--nulstiller max værdimin = math.huge--nulstiller min værdi med uendeligt stort talsum = 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")
fori, iteminipairs(data) doprice = 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 + pricegrp.checkupdate('13/4/' ..i, price)
item.hour = tonumber(item.HourDK:match('T(%d+)'))
--Gemmer prisen fra igår i datalager under Spotpris1...23 iftidtimer == 12andtidminutter == 00thenstorage.set('Spotpris' ..i, price)
endendavg = sum / #datagrp.checkupdate('13/4/25', avg)
grp.checkupdate('13/4/26', max)
grp.checkupdate('13/4/27', min)
table.sort(data, function(a, b)
returna.SpotPriceDKK < b.SpotPriceDKKend)
list = {}
fori = 1, 4doitem = data[ i ]
list[ #list + 1 ] = string.format('%d = %.2f', item.hour, item.SpotPriceDKK)
endhours = table.concat(list, '; ')
grp.checkupdate('13/4/28', hours)
-- viser angivede enheder i loggenlog(avg, max, min, tidtimer, tidminutter, hours)