To start with you can ignore the dzvents script. The first thing to do is to make sure you have the correct URL and you can develop that one just by pasting it into your browser and see what kind of results you get.
Here is an example of the URL that I use to get the prices (with my API token replaced by standard text)
https://web-api.tp.entsoe.eu/api?securi ... 2403062200
If you look at the dzvents (not LUA) script you can see how this URL is composed in the dzvent script.
You can only display those values into domoticz if you are able to load them onto a device. I don't know what device type you can use for this kind of data. Not sure if one exists. Maybe you have to use a separate device for each type of production.
It also depends on what you want to do with the data. Do you want to process it further or only display it. If it is just for display, you could load each value onto a separate device and then combine those devices as a stacked bar in dashticz. In that way you are replicating the ENTSOE graph in dashticz. Or, much easier, you could just embed the URL for the ENTSOE graph in a dashticz frame. Have a look in the dashticz manual in the paragraph about "frames".
If you really want to load the values into domoticz you have to use some kind of dzvents script, similar to the one used for loading prices. The principle of the script is that the script is first launched using a timer. This sends the http request. After that, the script is launched by the http response and the values from the response are processed onto devices. Have a look at the dzvents documentation for asynchronous http requests.
Here is my latest dzvents script to load the prices onto a managed counter for later display in domoticz and dashticz.
Code: Select all
-- Script to load day-ahead electricity prices into a managed counter.
-- The script loads prices excluding tax and including tax onto two managed counters and also uses a managed counter to indicate
-- the current hour, so that can be used in a graph to highlight that hour.
-- New prices are available every day at 15:00 for the coming 24 hrs.
-- These are base prices. Providers of dynamic electricity contracts will add their surcharges and government taxes to it.
-- API documentation at: https://transparency.entsoe.eu/content/static_content/Static%20content/web%20api/Guide.html
-- To get this data yourself (it is free):
-- 1) Register for an account at https://transparency.entsoe.eu/dashboard/show
-- 2) Send an email with subject "Restful API access" and your account email address in the body
-- 3) After receipt of their confirmation, go into your account and generate your token.
-- 4) Store the token in a domoticz user variable and note down the idx.
-- 5) Adapt the idx on the line below.
local Time = require('Time')
-- devices
local idxDynamicELPrices=177
local idxDynamicELPricesIncl=184
local idxCurrentHourIndicator=179
-- user variables
local idxEUtoken=12 -- idx of the user variable with the API token
local idxBTWpercentage=13 -- user variable with BTW/VAT percentage
local idxElTax=4 -- user variable for electricity tax, incl BTW
return {
on = {
timer = {
'at *:03', -- Timer to get new electricity prices. Adapt timer to your needs. Normally new electricty prices are available after 15:00.
},
httpResponses = {
'ELday1prices', -- must match with the callback passed to the openURL command in the code below
'ELday2prices', -- must match with the callback passed to the openURL command in the code below
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'EU future EL prices',
},
execute = function(domoticz, item)
if (item.isTimer) then
-- section to launch the EU electricity API get request
local UrlStart='https://web-api.tp.entsoe.eu/api?' -- the API website
local EUtoken=domoticz.variables(idxEUtoken) -- user variable with API token
local DocType='A44' -- day ahead prices document type
local PriceRegion='10YNL----------L' -- region is set to The Netherlands (adapt to your need as per API documentation)
--get data current day first
local dayahead=0
local PricePeriodStart=os.date("%Y%m%d",os.time() + dayahead) .. "0000" -- range 00:00 to 23:00, this will return full day anyway
local PricePeriodEnd=os.date("%Y%m%d", os.time() + dayahead) .. "2200"
-- compose the full URL
local EUurl=UrlStart .. 'securityToken=' .. EUtoken.value .. '&documentType=' .. DocType .. '&in_Domain=' .. PriceRegion .. '&out_Domain=' .. PriceRegion .. '&periodStart=' .. PricePeriodStart .. '&periodEnd=' .. PricePeriodEnd
domoticz.log("URL : " .. EUurl, domoticz.LOG_INFO)
-- launch the URL
domoticz.openURL({
url = EUurl,
method = 'GET',
callback = 'ELday1prices', -- must match httpResponses above
})
if Time().hour>=14 then
-- get the data for the second day
local dayahead=24*60*60
local PricePeriodStart=os.date("%Y%m%d",os.time() + dayahead) .. "0000" -- range 00:00 to 23:00, this will return full day anyway
local PricePeriodEnd=os.date("%Y%m%d", os.time() + dayahead) .. "2200"
-- compose the full URL
local EUurl=UrlStart .. 'securityToken=' .. EUtoken.value .. '&documentType=' .. DocType .. '&in_Domain=' .. PriceRegion .. '&out_Domain=' .. PriceRegion .. '&periodStart=' .. PricePeriodStart .. '&periodEnd=' .. PricePeriodEnd
domoticz.log("URL : " .. EUurl, domoticz.LOG_INFO)
-- launch the URL
domoticz.openURL({
url = EUurl,
method = 'GET',
callback = 'ELday2prices', -- must match httpResponses above
})
end
local PreviousHourDateTime=os.date("%Y-%m-%d %H:00:00",os.time() - 60*60)
domoticz.log("previous datetime " .. PreviousHourDateTime,domoticz.LOG_INFO)
local NextHourDateTime=os.date("%Y-%m-%d %H:00:00",os.time() + 60*60)
domoticz.log("next datetime " .. NextHourDateTime,domoticz.LOG_INFO)
domoticz.devices(idxCurrentHourIndicator).updateHistory(PreviousHourDateTime,"0;0")
domoticz.devices(idxCurrentHourIndicator).updateHistory(NextHourDateTime,"0;0")
else
if (item.isHTTPResponse) then
local CurrentHr=os.date("%H",os.time())
local CurrentDateTime=os.date("%Y-%m-%d %H:00:00",os.time())
-- response to openURL (HTTP GET) request was received
if (item.trigger=="ELday1prices") or (item.trigger=="ELday2prices") then
if (item.ok) then
if (item.isXML) then -- should be XML
--domoticz.log('start dumptable', domoticz.LOG_INFO)
--domoticz.utils.dumpTable(item.xml) -- dumpTable can be used for debugging
--domoticz.log('end dumptable', domoticz.LOG_INFO)
local responseKey=""
for key, value in pairs (item.xml) do
domoticz.log('item.xml first line key ' .. key , domoticz.LOG_INFO)
responseKey=key
end
if responseKey == "Publication_MarketDocument" then
local priceHourStr=""
local priceDate=""
local priceAmount=0
local inclAmount=0
local sValueStr=""
local inclSValueStr=""
for id = 1, 24 do
local priceHour=(id-1)
if priceHour<10 then
priceHourStr="0" .. priceHour
else
priceHourStr=priceHour
end
if (item.trigger=="ELday1prices") then
priceDate=os.date("%Y-%m-%d",os.time()) .. " " .. priceHourStr .. ":00:00"
else
priceDate=os.date("%Y-%m-%d",os.time() + 24*60*60) .. " " .. priceHourStr .. ":00:00"
end
priceAmount=domoticz.utils.round(item.xml.Publication_MarketDocument.TimeSeries.Period.Point[id]['price.amount']*100,0)
domoticz.log('priceDate ' .. priceDate .. " price " .. priceAmount , domoticz.LOG_INFO)
inclAmount=domoticz.utils.round(priceAmount*(1+domoticz.variables(idxBTWpercentage).value/100)+domoticz.variables(idxElTax).value*100000,0)
sValueStr="0;" .. priceAmount
inclSValueStr="0;"..inclAmount
domoticz.log('sValueStr ' .. sValueStr , domoticz.LOG_INFO)
domoticz.log('inclSValueStr ' .. inclSValueStr , domoticz.LOG_INFO)
domoticz.devices(idxDynamicELPrices).updateHistory(priceDate,sValueStr)
domoticz.devices(idxDynamicELPricesIncl).updateHistory(priceDate,inclSValueStr)
domoticz.log("current hr " .. CurrentHr,domoticz.LOG_INFO)
domoticz.log("price hr " .. priceHour,domoticz.LOG_INFO)
if (item.trigger=="ELday1prices") then
if tostring(CurrentHr)==tostring(priceHourStr) then
domoticz.devices(idxCurrentHourIndicator).updateHistory(CurrentDateTime,sValueStr)
domoticz.log("updating current hour " .. sValueStr,domoticz.LOG_INFO)
domoticz.devices(idxCurrentHourIndicator).updateCounter(priceAmount)
domoticz.devices(idxDynamicELPrices).updateCounter(priceAmount)
domoticz.devices(idxDynamicELPricesIncl).updateCounter(inclAmount)
end
end
end
else
domoticz.log("No price data received from trigger " .. item.trigger .. " key " .. responseKey, domoticz.LOG_INFO)
end
else
domoticz.log('No XML received', domoticz.LOG_INFO)
end
else
domoticz.log('There was a problem handling the request. Item not ok', domoticz.LOG_INFO)
domoticz.log(item, domoticz.LOG_INFO)
end
end
end
end
end
}
Update with additional thought: the display as a frame probably will not work because you need to pass a variable (today's date). I would not know how to do that.