Verwunderung bei Nutzung von %

Begonnen von stobor, 27 Mai 2016, 11:23:37

Vorheriges Thema - Nächstes Thema

stobor

Hallo, ich habe gelesen, dass es Änderungen mit der Version 5.7 gab. Jetzt verstehe ich nicht genau, wie ich meinen Code aktualisieren muss:


define BatteriewarnungNotify notify .*:[Bb]attery:.* {\
if(("%" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {\
system ("curl -s -F 'token=abc123' -F 'user=def456' -F 'message=Batteriewarnung\n@ %' https://pushdata.com/1/messages.json");;\
fhem "set vBatWarningNOTSent off";;\
}\


Nun taucht in der Anzeige nur noch das @ und % auf , aber nicht mehr der Gerätename und Wert. Kann mir jemand auf die Sprünge helfen, wie der Code zu ändern ist. Ich erkenne das aus der Doku nicht.
Danke
Intel NUC (Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-113-generic x86_64))  mit CUL V3.2 (FW 1.57 CUL868) für FS20 und CCU3 für HM(IP) + Arduino Mega (Firmata) - FHEM Revision: 29534 - FS20, HM(IP), MQTT, Philips HUE, ModBus

marvin78

Dem Link unter dem roten Text rechts oben bist du gefolgt? commandref zu notify wirklich gelesen? Da steht alles drin.

stobor

Ja, habe ich gelesen, mir ist es trotzdem nicht so ganz klar.

Heißt das, dass ich einfach
@ durch %NAME
und
% durch %EVENT
ersetze?

Also:

define BatteriewarnungNotify notify .*:[Bb]attery:.* {\
if(("%EVENT" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {\
system ("curl -s -F 'token=abc123' -F 'user=def456' -F 'message=Batteriewarnung\n%NAME %EVENT' https://pushdata.com/1/messages.json");;\
fhem "set vBatWarningNOTSent off";;\
}\

?
Intel NUC (Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-113-generic x86_64))  mit CUL V3.2 (FW 1.57 CUL868) für FS20 und CCU3 für HM(IP) + Arduino Mega (Firmata) - FHEM Revision: 29534 - FS20, HM(IP), MQTT, Philips HUE, ModBus

marvin78

Also nicht gelesen. Ich zitiere:

Text hinter dem Link rechts oben:

Zitat- @ und % im notify/etc gibts nicht mehr, genauso wie %NAME, %EVENT. Bitte stattdessen $NAME, $EVENT verwenden. Das ist uniform in fhem-Befehlen,  perl-Einzeiler {}, und im shell-Aufruf "" moeglich. Damit faellt auch die Notwendigkeit von @@/%% weg. Fuer Details siehe den (seit lange unveraenderten) commandref Eintrag fuer notify.

Text aus der commandref zu notify:

Zitat

       
  • in the command section you can access the event:

            
    • The variable $EVENT will contain the complete event, e.g. measured-temp: 21.7 (Celsius)
    • $EVTPART0,$EVTPART1,$EVTPART2,etc contain the space separated event parts (e.g. $EVTPART0="measured-temp:", $EVTPART1="21.7", $EVTPART2="(Celsius)". This data is available as a local variable in perl, as environment variable for shell scripts, and will be textually replaced for FHEM commands.
    • $NAME and $TYPE contain the name and type of the device triggering the event, e.g. myFht and FHT
  • Note: the following is deprecated and will be removed in a future release. It is only active for featurelevel up to 5.6. The described replacement is attempted if none of the above variables ($NAME/$EVENT/etc) found in the command.

            
    • The character % will be replaced with the received event, e.g. with on or off or measured-temp: 21.7 (Celsius)
      It is advisable to put the % into double quotes, else the shell may get a syntax error.
    • The character @ will be replaced with the device name.
    • To use % or @ in the text itself, use the double mode (%% or @@).
    • Instead of % and @, the parameters %EVENT (same as %), %NAME (same as @) and %TYPE (contains the device type, e.g.  FHT) can be used. The space separated event "parts" are available as %EVTPART0, %EVTPART1, etc.  A single % looses its special meaning if any of these parameters appears in the definition.
    [/l][/l]

     
Da steht alles drin.

[/list]

Leeloo_Dallas

#4
Hi stobor,

bei mir siehts, in einem anderen Zusammenhang, so aus und funktioniert:

Ich verwende z.Zt. hauptsächlich solche Konstrukte:

#=> Email- Senden bei gewünschtem Zustand von d_SAM
#ALARM,WARNUNG__Alarm,WARNUNG__Wasser,WARNUNG__ControlGroup,Klingel,intern_ein,extern_ein,intern_scharf,extern_scharf,unscharf
define n_StatusChange__d_SAM_chk notify d_SAM { \
my $s1 = Value("d_SAM");;\
my $g1 = Value("d_ControlGroup_intern");;\
my $g2 = Value("d_ControlGroup_extern");;\
my $w1 = Value("WassersensorHM__EG_Kueche");;\
my $w2 = Value("WassersensorHM__OG_Bad");;\
my $w3 = Value("WassersensorHM__DG_Waschraum");;\
if($s1 eq "ALARM" || $s1 eq "WARNUNG__Alarm" || $s1 eq "WARNUNG__Wasser" || $s1 eq "intern_ein" || $s1 eq "extern_ein"|| $s1 eq "intern_scharf" || $s1 eq "extern_scharf" || $s1 eq "Klingel" || $s1 eq "unscharf" ) {\
  { DebianMail ('Name@domain',"FHEM -SAM_Zustand-: $NAME / $EVENT","FHEM_Sam: Sam [$NAME] meldet folgenden Status [$EVENT]. \n \n ControllGroup: [$g1] / [$g2] \n WassersensorHM__EG_Kueche: [$w1] \n WassersensorHM__OG_Bad: [$w2] \n WassersensorHM__DG_Waschraum: [$w3] ")};;\
  Log 3, "@@: _!!!_SAM_Zustand_!!!_ %%";;\
}\
}
attr n_StatusChange__d_SAM_chk group System_Notifys
attr n_StatusChange__d_SAM_chk room SYSTEM
#=> Email- Senden bei gewünschten Zustand von d_SAM


Vielleicht hilft's ja zum Verstehen der Logik !??!

Folgendes funktioniert auch :
#Email- Senden bei Battery-Änderung: WassersensorHM__OG_Bad
define n_WassersensorHM__OG_Bad_battery_chk notify WassersensorHM__OG_Bad:[Bb]attery.* { \
if($EVENT !~ m/ok/) {\
  { DebianMail ('Name@domain.de',"FHEM -Wassersensor-Meldung-: $NAME / $EVENT","FHEM: Das Gerät [$NAME] meldet folgenden Status [$EVENT].")};;\
  Log 3, "@@: Wassersensor-Meldung %%";;\
}\
}
attr n_WassersensorHM__OG_Bad_battery_chk group System_Notifys
attr n_WassersensorHM__OG_Bad_battery_chk room SYSTEM



Hierbei stehe ich jedoch selbst noch auf dem Schlauch und bräuchte Hilfe.
Wie genau wird "m/ok/" interpretiert?
Besser was bedeutet "m/" ?

Habe schon öfter danach gesucht, aber noch nix gefunden was mir auf die Sprünge hilft.

Gruß,
Leeloo
Greatz Leeloo

marvin78

Das hat hiermit gar nichts zu tun. Hier geht es nur um die "Platzhalter" bzw. Variablen, in denen Name, Typ und Event für ein notify stehen. Diese lauten schon länger $NAME, $TYPE und $EVENT.

Bei dir @Leeloo_Dallas geht es um Regex. Hier ein Link für dich

https://danielfett.de/de/tutorials/tutorial-regulare-ausdrucke/

Leeloo_Dallas

#6
Sorry, wollte nur ein Beispiel liefern, welches die Verwendung von $NAME, $EVENT und sonstiger Variablen im notify aufzeigt.
Kommt nicht mehr vor  :-X

Danke für den Link bzgl. RegEx. Die Seite faßt das Thema super zusammenfaßt.  ;D

Nachtrag:
Da ich jetzt weiß wonach ich Suchen musste.
Hier noch ein Link zum Thema "Perl/Reguläre Ausdrücke" => https://wiki.selfhtml.org/wiki/Perl/Regul%C3%A4re_Ausdr%C3%BCcke
Greatz Leeloo

stobor

#7
So richtig komme ich nicht weiter. Kann mir noch jemand einen Tipp geben?

So sah es bisher aus:

define SC_MAX_OG_opened notify SC_MAX_OG_.*:opened.* {\
fhem "set Fensterkontrolle on";;\
if (Value("Abwesend") eq "on" && !(Value("alle_Lampen") eq "on")) {\
fhem "set alle_Lampen on";;\
system ("curl -s -F 'token=abc1234' -F 'user=def456' -F 'message=Fenster geöffnet\n@ %' https://pushdata.com/1/messages.json");;\
}\
}

define BatteriewarnungNotify notify .*:[Bb]attery:.* {\
if(("%" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {\
system ("curl -s -F 'token=abc123' -F 'user=def456' -F 'message=Batteriewarnung\n@ %' https://pushdata.com/1/messages.json");;\
fhem "set vBatWarningNOTSent off";;\
}\
}


Daraus habe ich dieses gemacht:

define SC_MAX_OG_opened notify SC_MAX_OG_.*:opened.* {\
fhem "set Fensterkontrolle on";;\
if (Value("Abwesend") eq "on" && !(Value("alle_Lampen") eq "on")) {\
fhem "set alle_Lampen on";;\
system ("curl -s -F 'token=abc1234' -F 'user=def456' -F 'message=Fenster geöffnet!!\n$NAME $EVTPART0 $EVTPART1'  https://pushdata.com/1/messages.json");;\
}\
}

define BatteriewarnungNotify notify .*:[Bb]attery:.* {\
if(("$EVTPART1" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {\
system ("curl -s -F 'token=abc123' -F 'user=def456' -F 'message=Batteriewarnung!\n$NAME $EVTPART0 $EVTPART1'  https://pushdata.com/1/messages.json");;\
fhem "set vBatWarningNOTSent off";;\
}\
}


Leider kommen nach der Änderung nur Batteriewarnungen, obwohl eigentlich ein Fenster geöffnet wurde, und die geöffnet Meldung hätte kommen müssen.

Im Log hab ich noch dies gefunden:

2016.05.30 18:07:07 4: CUL_Parse: CUL_1 Z0BAA063011FF660E35450012E0 -90
2016.05.30 18:07:07 5: CUL_1 dispatch Z0BAA063011FF660E35450012
2016.05.30 18:07:07 5: CUL_MAX_Parse: len 11, msgcnt AA, msgflag 06, msgTypeRaw ShutterContactState, src 11ff66, dst 0e3545, groupid 0, payload 12
2016.05.30 18:07:07 5: CUL_MAX_Parse: rssi: -90
2016.05.30 18:07:07 5: cm dispatch MAX,0,ShutterContactState,11ff66,12
2016.05.30 18:07:07 5: MAX_Parse MAX,0,ShutterContactState,11ff66,12
2016.05.30 18:07:07 5: ShutterContact isopen 1, rferror 0, battery 0, unkbits 0
2016.05.30 18:07:07 5: Triggering SC_MAX_OG_Badezimmer (4 changes)
2016.05.30 18:07:07 5: Starting notify loop for SC_MAX_OG_Badezimmer, first event battery: ok
2016.05.30 18:07:07 5: Triggering BatteriewarnungNotify
2016.05.30 18:07:07 4: BatteriewarnungNotify exec {
if(("ok" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {
system ("curl -s -F 'token=xxx' -F 'user=xxx' -F 'message=Batteriewarnung!!\n$NAME $EVTPART0 $EVTPART1'  https://api.pushover.net/1/messages.json");;
fhem "set vBatWarningNOTSent off";;
}
}
2016.05.30 18:07:07 5: Cmd: >{
if(("ok" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {
system ("curl -s -F 'token=xxx' -F 'user=xxx' -F 'message=Batteriewarnung!!\n$NAME $EVTPART0 $EVTPART1'  https://api.pushover.net/1/messages.json");
fhem "set vBatWarningNOTSent off";
}
}<
2016.05.30 18:07:07 5: Triggering SC_MAX_OG_opened
2016.05.30 18:07:07 4: SC_MAX_OG_opened exec {
fhem "set Fensterkontrolle on";;
if (Value("Abwesend") eq "on" && !(Value("alle_Lampen") eq "on")) {
fhem "set alle_Lampen on";;
system ("curl -s -F 'token=xxx' -F 'user=xxx' -F 'message=Fenster geöffnet!!\n$NAME $EVTPART0 $EVTPART1'  https://api.pushover.net/1/messages.json");;
}
}
2016.05.30 18:07:07 5: Cmd: >{
fhem "set Fensterkontrolle on";
if (Value("Abwesend") eq "on" && !(Value("alle_Lampen") eq "on")) {
fhem "set alle_Lampen on";
system ("curl -s -F 'token=xxx' -F 'user=xxx' -F 'message=Fenster geöffnet!!\n$NAME $EVTPART0 $EVTPART1'  https://api.pushover.net/1/messages.json");
}
}<
2016.05.30 18:07:07 3: SC_MAX_OG_opened return value: Global symbol "$EVTPART1" requires explicit package name at (eval 148) line 5.
Intel NUC (Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-113-generic x86_64))  mit CUL V3.2 (FW 1.57 CUL868) für FS20 und CCU3 für HM(IP) + Arduino Mega (Firmata) - FHEM Revision: 29534 - FS20, HM(IP), MQTT, Philips HUE, ModBus

CoolTux


SC_MAX_OG_opened return value: Global symbol "$EVTPART1" requires explicit package name at (eval 148) line 5.


Die Fehlermeldung ist doch eindeutig. Dein SC_MAX_OG liefert anscheinend als Event kein EVTPART1.
Schau doch erstmal was überhaupt als Event an kommt. Thema Eventmonitor.
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

stobor

Ich übermittle jetzt einfach $EVENT anstatt $EVTPART0 oder $EVTPART1. Das scheint besser zu laufen.

---

Bei der Batteriewarnung möchte ich ja ermitteln, ob die Meldung KEIN "OK" enthält:
define BatteriewarnungNotify notify .*:[Bb]attery:.* {\
if(("%" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {\
system ("curl -s -F 'token=abc123' -F 'user=def456' -F 'message=Batteriewarnung\n@ %' https://pushdata.com/1/messages.json");;\
fhem "set vBatWarningNOTSent off";;\
}\
}


Kann ich das % innerhalb der Anführungszeichen der IF-Abfrage tatsächlich einfach durch $EVENT ersetzen? Also so:
define BatteriewarnungNotify notify .*:[Bb]attery:.* {\
if(("$EVENT" !~ m/ok/) && (Value("vBatWarningNOTSent") eq "on")) {\
system ("curl -s -F 'token=abc123' -F 'user=def456' -F 'message=Batteriewarnung!\n$NAME $EVENT' https://pushdata.com/1/messages.json");;\
fhem "set vBatWarningNOTSent off";;\
}\
}
Intel NUC (Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-113-generic x86_64))  mit CUL V3.2 (FW 1.57 CUL868) für FS20 und CCU3 für HM(IP) + Arduino Mega (Firmata) - FHEM Revision: 29534 - FS20, HM(IP), MQTT, Philips HUE, ModBus

CoolTux

Probiere es aus. Du kannst mit trigger ja testen.
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

stobor

Wie kann ich denn dieses Notify mit einem Trigger ansprechen?
Intel NUC (Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-113-generic x86_64))  mit CUL V3.2 (FW 1.57 CUL868) für FS20 und CCU3 für HM(IP) + Arduino Mega (Firmata) - FHEM Revision: 29534 - FS20, HM(IP), MQTT, Philips HUE, ModBus

CoolTux

Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net