Zwei unterschiedliche HTTPMOD abfragen Sommer/Winterzeit

Begonnen von privat58, 07 November 2022, 07:27:03

Vorheriges Thema - Nächstes Thema

privat58

Hallo, ich habe ein HTTPMOD device, was mir die aktuellen Strompreise ausliest und in schwedische Oere umrechnet.
Die def habe ich jetzt auf Winterzeit umgestellt.
defmod entsoe_price_today HTTPMOD https://transparency.entsoe.eu/api?securityToken=%%token%%&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=%%today%%0000&periodEnd=%%today%%2300 86400
attr entsoe_price_today alignTime 00:00:05
attr entsoe_price_today event-on-change-reading .*
attr entsoe_price_today reading01Format %.2f
attr entsoe_price_today reading01Name abs_00_amount
attr entsoe_price_today reading01OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading01Regex position>1<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading02Format %.2f
attr entsoe_price_today reading02Name abs_01_amount
attr entsoe_price_today reading02OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading02Regex position>2<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading03Format %.2f
attr entsoe_price_today reading03Name abs_02_amount
attr entsoe_price_today reading03OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading03Regex position>3<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading04Format %.2f
attr entsoe_price_today reading04Name abs_03_amount
attr entsoe_price_today reading04OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading04Regex position>4<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading05Format %.2f
attr entsoe_price_today reading05Name abs_04_amount
attr entsoe_price_today reading05OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading05Regex position>5<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading06Format %.2f
attr entsoe_price_today reading06Name abs_05_amount
attr entsoe_price_today reading06OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading06Regex position>6<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading07Format %.2f
attr entsoe_price_today reading07Name abs_06_amount
attr entsoe_price_today reading07OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading07Regex position>7<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading08Format %.2f
attr entsoe_price_today reading08Name abs_07_amount
attr entsoe_price_today reading08Regex position>8<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading09Format %.2f
attr entsoe_price_today reading09Name abs_08_amount
attr entsoe_price_today reading09OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading09Regex position>9<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading10Format %.2f
attr entsoe_price_today reading10Name abs_09_amount
attr entsoe_price_today reading10OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading10Regex position>10<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading11Format %.2f
attr entsoe_price_today reading11Name abs_10_amount
attr entsoe_price_today reading11OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading11Regex position>11<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading12Format %.2f
attr entsoe_price_today reading12Name abs_11_amount
attr entsoe_price_today reading12OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading12Regex position>12<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading13Format %.2f
attr entsoe_price_today reading13Name abs_12_amount
attr entsoe_price_today reading13OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading13Regex position>13<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading14Format %.2f
attr entsoe_price_today reading14Name abs_13_amount
attr entsoe_price_today reading14OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading14Regex position>14<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading15Format %.2f
attr entsoe_price_today reading15Name abs_14_amount
attr entsoe_price_today reading15OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading15Regex position>15<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading16Format %.2f
attr entsoe_price_today reading16Name abs_15_amount
attr entsoe_price_today reading16OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading16Regex position>16<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading17Format %.2f
attr entsoe_price_today reading17Name abs_16_amount
attr entsoe_price_today reading17OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading17Regex position>17<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading18Format %.2f
attr entsoe_price_today reading18Name abs_17_amount
attr entsoe_price_today reading18OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading18Regex position>18<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading19Format %.2f
attr entsoe_price_today reading19Name abs_18_amount
attr entsoe_price_today reading19OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading19Regex position>19<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading20Format %.2f
attr entsoe_price_today reading20Name abs_19_amount
attr entsoe_price_today reading20OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading20Regex position>20<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading21Format %.2f
attr entsoe_price_today reading21Name abs_20_amount
attr entsoe_price_today reading21OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading21Regex position>21<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading22Format %.2f
attr entsoe_price_today reading22Name abs_21_amount
attr entsoe_price_today reading22OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading22Regex position>22<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading23Format %.2f
attr entsoe_price_today reading23Name abs_22_amount
attr entsoe_price_today reading23OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading23Regex position>23<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today reading24Format %.2f
attr entsoe_price_today reading24Name abs_23_amount
attr entsoe_price_today reading24OExpr $val * ReadingsVal('Kurs_EUR_SEK','EURSEK',0) / 10
attr entsoe_price_today reading24Regex position>24<\Sposition>\n\t*<price\Samount>(-?[\d.]+)
attr entsoe_price_today replacement01Mode text
attr entsoe_price_today replacement01Regex %%token%%
attr entsoe_price_today replacement01Value xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
attr entsoe_price_today replacement02Mode expression
attr entsoe_price_today replacement02Regex %%today%%
attr entsoe_price_today replacement02Value {strftime("%Y%m%d", localtime( time))}
attr entsoe_price_today replacement03Mode expression
attr entsoe_price_today replacement03Regex %%yesterday%%
attr entsoe_price_today replacement03Value {strftime("%Y%m%d", localtime(time-86400))}
attr entsoe_price_today room Energie
attr entsoe_price_today stateFormat entsoe_price_now

In der Sommerzeit war die def
https://transparency.entsoe.eu/api?securityToken=%%token%%&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=%%yesterday%%2300&periodEnd=%%today%%2300 86400
Mit "periodStart" und "periodEnd" bestimmt man die Zeiten, die man lesen möchte. Dadurch das der Startzeitpunkt einmal heute liegt und einmal gestern, kommt mir nur der Gedanke, dies in einem DOIF zu ändern.
Kann man in einem DOIF die def eines devices ändern?
Die andere Möglichkeit wäre eventuell in einem replacementValue das Sommerzeitabhängig im Perlmodus zu machen, da blicke ich aber nicht durch.
Die Sommer/Winterzeit Umstellung habe ich schon in einem DOIF für andere Sachen.
defmod Sommerzeit DOIF ##Feststellung ob Sommerzeit oder Winterzeit\
##\
(([02:00] or [03:00]) and $isdst) DOELSE

Eventuell hat jemand eine andere Idee.
Danke

ch.eick

Zitat von: privat58 am 07 November 2022, 07:27:03
Hallo, ich habe ein HTTPMOD device, was mir die aktuellen Strompreise ausliest und in schwedische Oere umrechnet.
Die def habe ich jetzt auf Winterzeit umgestellt.
defmod entsoe_price_today HTTPMOD https://transparency.entsoe.eu/api?securityToken=%%token%%&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=%%today%%0000&periodEnd=%%today%%2300 86400
< snip >
attr entsoe_price_today stateFormat entsoe_price_now

In der Sommerzeit war die def
https://transparency.entsoe.eu/api?securityToken=%%token%%&documentType=A44&in_Domain=10Y1001A1001A46L&out_Domain=10Y1001A1001A46L&periodStart=%%yesterday%%2300&periodEnd=%%today%%2300 86400
Mit "periodStart" und "periodEnd" bestimmt man die Zeiten, die man lesen möchte. Dadurch das der Startzeitpunkt einmal heute liegt und einmal gestern, kommt mir nur der Gedanke, dies in einem DOIF zu ändern.
Kann man in einem DOIF die def eines devices ändern?
Die andere Möglichkeit wäre eventuell in einem replacementValue das Sommerzeitabhängig im Perlmodus zu machen, da blicke ich aber nicht durch.
Die Sommer/Winterzeit Umstellung habe ich schon in einem DOIF für andere Sachen.
defmod Sommerzeit DOIF ##Feststellung ob Sommerzeit oder Winterzeit\
##\
(([02:00] or [03:00]) and $isdst) DOELSE

Eventuell hat jemand eine andere Idee.
Danke

Moin,
Du kannst im HTTPMOD mit replacement und Perl Dein URL Parameter dynamisch erstellen.

VG   Christian
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

privat58

Hallo,
bisher hatte ich das so:
attr entsoe_price_today replacement02Mode expression
attr entsoe_price_today replacement02Regex %%today%%
attr entsoe_price_today replacement02Value {strftime("%Y%m%d", localtime( time))}



Du meinst so in der Richtung?
{ if
  (($isdst = 1) {{strftime("%Y%m%d", localtime(time-86400))}2300 })
  elseif
  (($isdst = 0) {{strftime("%Y%m%d", localtime(time-86400))}2200 })
  }

Das ganze müsste ich dann durchprobieren, bis es klappt. Perl ist nicht meine Stärke. Da sind Bienen oder Autos leichter zu verstehen :-)

privat58

da ich mir erst einmal nicht anders zu helfen wusste, habe ich das mit einem DOIF probiert.
defmod Strom_Kosten_entsoe_Sommerzeit DOIF ([Sommerzeit:state] eq "Sommerzeit" )(attr entsoe_price_today_test replacement04Value 2200)\
DOELSEIF\
([Sommerzeit:state] eq "Winterzeit" )(attr entsoe_price_today_test replacement04Value 2300)\
attr Strom_Kosten_entsoe_Sommerzeit room DOIF,Energie

Das sollte erst einmal funktionieren.

ch.eick

#4
Zitat von: privat58 am 15 November 2022, 17:09:36
Du meinst so in der Richtung?
{ if
  (($isdst == 1) {{strftime("%Y%m%d", localtime(time-86400))}2300 })
  elseif
  (($isdst == 0) {{strftime("%Y%m%d", localtime(time-86400))}2200 })
  }

Das ganze müsste ich dann durchprobieren, bis es klappt. Perl ist nicht meine Stärke. Da sind Bienen oder Autos leichter zu verstehen :-)
Hallo,
ich verstehe das mit 2300 oder 2200 nicht, da kommt bei mir ein Syntax Error.

Ansonsten hast Du hier ja bereits Perl verwendet.

attr entsoe_price_today replacement03Value {strftime("%Y%m%d", localtime(time-86400))}

Da ginge dann auch eine if Abfrage, die auch komplexer sein kann, quasi ein ganzes Perl Programm.

attr entsoe_price_today replacement03Value { ($isdst == 1)?strftime("%Y%m%d", localtime(time-86400))2300:strftime("%Y%m%d", localtime(time-86400))2200 }
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

privat58

Hallo ,
das 2200 steht für 22:00Uhr zur Sommerzeit und das 2300 für 23:00 in der Winterzeit.
Die Abfrage bei entsoe ist nur per UTC möglich.
Im Sommer muss ich abfragen ab gestern 22Uhr bis heute 22Uhr.
Das Format beim Abfragen ist
periodStart=%%yesterday%%%%Zeit%%&periodEnd=%%today%%%%Zeit%%
Ich hatte die Zeit erst fest in der Abfrage rein geschrieben. Jetzt habe ich das noch einmal geteilt, das die Zeit separat abgefragt werden kann.
Das "yesterday" habe ich so gelöst {strftime("%Y%m%d", localtime(time-86400))},
das "today" so {strftime("%Y%m%d", localtime( time))}
Nun sollte %%Zeit%% noch nach Sommer/Winterzeit  mit 2200 oder 2300 ersetzt werden.

ch.eick

Zitat von: privat58 am 16 November 2022, 18:41:07
Hallo ,
das 2200 steht für 22:00Uhr zur Sommerzeit und das 2300 für 23:00 in der Winterzeit.
Die Abfrage bei entsoe ist nur per UTC möglich.
Im Sommer muss ich abfragen ab gestern 22Uhr bis heute 22Uhr.
Das Format beim Abfragen ist
periodStart=%%yesterday%%%%Zeit%%&periodEnd=%%today%%%%Zeit%%
Ich hatte die Zeit erst fest in der Abfrage rein geschrieben. Jetzt habe ich das noch einmal geteilt, das die Zeit separat abgefragt werden kann.
Das "yesterday" habe ich so gelöst {strftime("%Y%m%d", localtime(time-86400))},
das "today" so {strftime("%Y%m%d", localtime( time))}
Nun sollte %%Zeit%% noch nach Sommer/Winterzeit  mit 2200 oder 2300 ersetzt werden.
Dann musst Du das auf zwei replacements aufteilen, den Dein Perl Syntax funktioniert so nicht.
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

privat58

Danke erst einmal. Eigentlich sollte nur noch das %%Zeit%% gesetzt werden, da beide Zeiten der Abfrage jeweils gleich sind. Entweder 2200 oder 2300.
Im Momnet klappt es erst einmal mit dem DOIF, was ich oben gezeigt habe. Damit wird das attr halt zweimal im Jahr gewechselt.

ch.eick

#8
Zitat von: privat58 am 17 November 2022, 17:02:47
Danke erst einmal. Eigentlich sollte nur noch das %%Zeit%% gesetzt werden, da beide Zeiten der Abfrage jeweils gleich sind. Entweder 2200 oder 2300.
Im Momnet klappt es erst einmal mit dem DOIF, was ich oben gezeigt habe. Damit wird das attr halt zweimal im Jahr gewechselt.
Du brauchst doch nur das %%Zeit%% auch als replacement zu definieren und das mit dem

attr entsoe_price_today replacement04Mode expression
attr entsoe_price_today replacement04Regex %%Zeit%%
attr entsoe_price_today replacement04Value { ($isdst == 1)?2300:2200 }         <<< hier ist das If/then/else

ersetzen lassen.
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

privat58

#9
das
($isdst = 1)?2200:2300 }
hatte ich schon versucht.
2022.11.17 22:25:29 3: entsoe_price_today_test: Replacement 04 with expression package main; { ($isdst = 1)?2200:2300 } and regex (?^:%%Zeit%%) created warning: Use of uninitialized value in substitution iterator at ./FHEM/98_HTTPMOD.pm line 896.

2022.11.17 22:25:29 3: entsoe_price_today_test: Replacement 04 with expression package main; { ($isdst = 1)?2200:2300 } and regex (?^:%%Zeit%%) created warning: Found = in conditional, should be == at (eval 25291211) line 1.

ein
($isdst ==1)?2200:2300 }
brachte diesen Fehler im log
2022.11.17 22:28:00 3: entsoe_price_today_test: Replacement 04 with expression package main; { ($isdst == 1)?2200:2300 } and regex (?^:%%Zeit%%) created warning: Use of uninitialized value in substitution iterator at ./FHEM/98_HTTPMOD.pm line 896.[code]
Daher wusste ich erst einmal nicht weiter.

frank

FHEM: 6.0(SVN) => Pi3(buster)
IO: CUL433|CUL868|HMLAN|HMUSB2|HMUART
CUL_HM: CC-TC|CC-VD|SEC-SD|SEC-SC|SEC-RHS|Sw1PBU-FM|Sw1-FM|Dim1TPBU-FM|Dim1T-FM|ES-PMSw1-Pl
IT: ITZ500|ITT1500|ITR1500|GRR3500
WebUI [HMdeviceTools.js (hm.js)]: https://forum.fhem.de/index.php/topic,106959.0.html

privat58

Sorry in meinem letzten Beitrag hat ein = gefehlt.
($isdst == 1)?2200:2300
bringt den Fehler
entsoe_price_today_test: Replacement 04 with expression package main; ($isdst == 1)?2200:2300 and regex (?^:%%Zeit%%) created warning: Use of uninitialized value in substitution iterator at ./FHEM/98_HTTPMOD.pm line 896.
entsoe_price_today_test: Replacement 04 with expression package main; ($isdst == 1)?2200:2300 and regex (?^:%%Zeit%%) created warning: Use of uninitialized value in substitution iterator at ./FHEM/98_HTTPMOD.pm line 896.

habe es jetzt erst einmal so gelöst und das DOIF was das attr ändert gelöscht.
{if(Value("Sommerzeit") eq "Sommerzeit") {2200} else {2300}}