Script with Dutch power prices - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Script with Dutch power prices (/showthread.php?tid=4068) |
Script with Dutch power prices - jeroen@stevens.biz - 29.05.2022 Hi. I want to read out the current hourly power prices (Dutch EPEX spot market). With this info I want to switch on heavy power users (car charging, airco etc) and switch off my solar panels when the market prices are below -/-0,06729 per kWh (since then the energy taxes don't compensate the negative market price, taxes are 0,03679 per kWh + 0,0305 per kWh). I found a website where I can read out these prices, but how can I let a script return the hourly values in a way I can make decisions with it? With this simple script (where I've put in the time range of 1 day), I get the following output; --/-- local https = require('ssl.https') local ltn12 = require('ltn12') local json = require('json') local cBody = 'TariffReturn' local cReq = {} result1 = https.request({ url = 'https://mijn.easyenergy.com/nl/api/tariff/getapxtariffs?startTimestamp=2022-05-29T22%3A00%3A00.000Z&endTimestamp=2022-05-30T22%3A00%3A00.000Z&grouping=', method = 'GET', headers = { ['content-length'] = #cBody, ['content-type'] = 'application/json' }, source = ltn12.source.string(cBody), sink = ltn12.sink.table(cReq) }) if (cReq) then mydata = json.pdecode(table.concat(cReq)) log(mydata) end --/-- In the output I refer to this part: --/ .... [4] * table: ["Timestamp"] * string: 2022-05-30T01:00:00+00:00 ["TariffReturn"] * number: 0.1845 ["TariffUsage"] * number: 0.223245 ["SupplierId"] * number: 0 /-- where ' ["TariffReturn"] * number: 0.1845 the price per kWh is for every kWh consumed (or delivered) between 2022-05-30, 04.00 - 05.00u The notation is a little bit confusion, since the table states it is at 01.00. I check the output of easyenergy with one of the other EPEX spot market parties: https://prijzen.powerhouse.net/forecast/ Any help is welcome. Jeroen RE: Script with Dutch power prices - Daniel - 30.05.2022 log(mydata[4].TariffReturn) RE: Script with Dutch power prices - admin - 30.05.2022 Try this, it will automatically use current date time and will provide prices for the current and the next hour. Code: json = require('json') RE: Script with Dutch power prices - jeroen@stevens.biz - 30.05.2022 Thanks Admin, this works like a charm. I only had to make a little adjustment, since the price of 'now' is the price for the 'next hour'. Some for the price of 'next hour', that is the price of 2 hours later. I guess this script shall be helpfull to many more people in the future since the power prices are so changing every hour. Greets Jeroen RE: Script with Dutch power prices - admin - 31.05.2022 Check that you have correct timezone set in Date/Time settings. Reported time is in UTC so incorrect timezone can explain 1 hour shift. RE: Script with Dutch power prices - JASK - 15.03.2023 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') I'm having a bit of trouble getting the data out. RE: Script with Dutch power prices - admin - 16.03.2023 '14ByteAsc' is not a valid data type use dt.string instead (without quotes). You also need to setup your script to run at a certain time when tomorrow prices become available. Right now it returns 404 because the data is not available yet. |