How to use PAIRS with ENTSOE multiple Timeseries

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Wilop91
Posts: 44
Joined: Tuesday 05 March 2024 17:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: France
Contact:

How to use PAIRS with ENTSOE multiple Timeseries

Post by Wilop91 »

Hello
This topic is related with the following topic I created earlier:
https://www.domoticz.com/forum/viewtopic.php?t=42104

I had to write 2 different dzVents scripts:
- one when ENTSOE returns a set of data containing a single Timeserie
- one when ENTSOE returns a set of data containing multiple Timeseries

Here is a link which shows a dataset with a single Timeseries
https://web-api.tp.entsoe.eu/api?securi ... 2404092300

And this is a link which shows a dataset with multiple Timeseries
https://web-api.tp.entsoe.eu/api?securi ... 2404092300

In both cases I retrieve the amount of MWH generated in France per hour and per "Generation Type" for a selected day (typically yesterday)

I use the following syntax to find the Timeseries in the received XML dataset:

Code: Select all

for key, value in pairs (item.xml.GL_MarketDocument.TimeSeries) do idx = idx + 1 end
When there are multiple Timeseries, this returns the number of Timeseries found.
However when there is only a single Timeserie, this do not return 1 as I would expect but the number of Tags in GL_MarketDocument (8 in this case)

While having 2 scripts is not really a problem, I just would like to know if there is a solution (PAIRS or something else) which allows to determine for both cases the number of Timeseries so that I can have a single script that handles both cases.

Thanks a lot in advance

Willy
User avatar
waltervl
Posts: 5791
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: How to use PAIRS with ENTSOE multiple Timeseries

Post by waltervl »

This is more Lua then dzvents. Search your answer in Lua references.

Btw, the examples do not work, perhaps post them in original text (perhaps limited if large series)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Wilop91
Posts: 44
Joined: Tuesday 05 March 2024 17:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: France
Contact:

Re: How to use PAIRS with ENTSOE multiple Timeseries

Post by Wilop91 »

Hello waltervl, thanks for your reply.
Actually I replaced PAIRS by this code

Code: Select all

idxMax = 0
for myKey, myValue in next, (item.xml.Publication_MarketDocument) do if (myKey == "TimeSeries") then idxMax = idxMax + 1 end end
This seems to work but still when processing the Timeseries I need to do this:

Code: Select all

if (idxMax == 1 ) then --dataset has only 1 Timeseries
	enumerate_timeseries(1, item.xml.Publication_MarketDocument.TimeSeries)
else -- the dataset has several Timeseries
	for idx = 1, idxMax do --Loop trough all the Timeseries
       		enumerate_timeseries(idx, item.xml.Publication_MarketDocument.TimeSeries[idx])
    	end
end
I'm still testing...and progressing slowly in LUA coding...

PS: in the ENTSOE links you need to enter your API token.

BR

Willy
Post Reply

Who is online

Users browsing this forum: ezrad and 1 guest