FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: stobor am 27 Mai 2016, 11:23:37

Titel: Verwunderung bei Nutzung von %
Beitrag von: stobor am 27 Mai 2016, 11:23:37
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
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: marvin78 am 27 Mai 2016, 11:27:41
Dem Link unter dem roten Text rechts oben bist du gefolgt? commandref zu notify wirklich gelesen? Da steht alles drin.
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: stobor am 27 Mai 2016, 11:34:02
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";;\
}\

?
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: marvin78 am 27 Mai 2016, 11:52:44
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]
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: Leeloo_Dallas am 27 Mai 2016, 11:57:49
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
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: marvin78 am 27 Mai 2016, 12:02:53
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/
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: Leeloo_Dallas am 27 Mai 2016, 12:11:32
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 (https://wiki.selfhtml.org/wiki/Perl/Regul%C3%A4re_Ausdr%C3%BCcke)
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: stobor am 30 Mai 2016, 18:00:28
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.
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: CoolTux am 30 Mai 2016, 18:40:13

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.
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: stobor am 30 Mai 2016, 20:45:54
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";;\
}\
}
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: CoolTux am 30 Mai 2016, 21:20:14
Probiere es aus. Du kannst mit trigger ja testen.
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: stobor am 30 Mai 2016, 21:42:22
Wie kann ich denn dieses Notify mit einem Trigger ansprechen?
Titel: Antw:Verwunderung bei Nutzung von %
Beitrag von: CoolTux am 30 Mai 2016, 21:47:04
grüne Box am rechten Rand (http://www.fhemwiki.de/wiki/Notify)