Trigger will nicht so wie ich will

Begonnen von Sailor, 06 Dezember 2013, 14:58:57

Vorheriges Thema - Nächstes Thema

Sailor

Ein herzerfrischendes MoinMoin an die fhem Gemeinde


Ich versuche mich heute mal mit meinem ersten Beitrag bzw. Frage und probiere auf diesem Wege gleich mal diesen Editor hinsichtlich Code-Fenster und Fussnoten aus.  ;)
Kritik hinsichtlich der Gestaltung dieses Beitrages ist Willkommen. Man ist ja Verbesserungswillig!  :)


Mein Problem:
Ich moechte mit dem "trigger" - Befehl eine notify routine testen welche mir eine email ueber den Batteriestatus versendet aber diese wird scheinbar nicht ausgefuehrt.

Meine vergeblichen Versuche in der fhem Befehlszeile waren wie folgt:
trigger Bat_BR_Window
trigger Bat_BR_Window low
trigger Bat_BR_Window battery:low
trigger Bat_BR_Window BR_Window.battery:low


Notify Routine in fhem.cfg:
define Bat_BR_Window notify BR_Window.battery.* {evtHandlerBattery('BR_Window',ReadingsVal("BR_Window", "battery", "default"));;}

Gebe ich den hinteren Teil dieses Codes {evtHandlerBattery('BR_Window',ReadingsVal("BR_Window", "battery", "default"));;} allerdings direkt in die Befehlszeile von fhem ein, funktioniert alles bestens! Die email kommt an wie sie soll!

Habe ich den trigger-Befehl falsch verstanden?


Ich habe mir aus den verschiedenen Wikis und Forumsbeitraegen
Batterieueberwachung: http://www.fhemwiki.de/wiki/Batterie%C3%BCberwachung
email versenden: http://www.fhemwiki.de/wiki/E-Mail_senden#Fritz.21Box_7390
folgenden Code zusammengestellt:

fhem.cfg:
attr global autoload_undefined_devices 1
attr global logfile ./log/fhem-%Y-%m.log
attr global modpath .
attr global motd 1
attr global sendStatistics onUpdate
attr global statefile ./log/fhem.save
attr global uniqueID ./FHEM/FhemUtils/uniqueID
attr global userattr devStateIcon devStateStyle icon sortby webCmd
attr global verbose 3

#Define Port for Telnet Access
define telnetPort telnet 7072 global

#Define Port for computer with normal, big screen and dark style
define WEB FHEMWEB 8083 global
attr WEB stylesheetPrefix dark

#Define Port for SmartPhone with small screen and dark style
define WEBphone FHEMWEB 8084 global
attr WEBphone stylesheetPrefix smallscreen dark

#Define Port for Tablet PCs with a tablet screen and dark style
define WEBtablet FHEMWEB 8085 global
attr WEBtablet stylesheetPrefix touchpad dark


# Fake FileLog entry, to access the fhem log from FHEMWEB
define Logfile FileLog ./log/fhem-%Y-%m.log fakelog

###START### Initialize autocreate ###START###
define autocreate autocreate
attr autocreate autosave 1
attr autocreate device_room %TYPE
attr autocreate filelog ./log/%NAME-%Y.log
attr autocreate weblink 1
attr autocreate weblink_room Plots
####END#### Initialize autocreate ####END####

# Disable this to avoid looking for new USB devices on startup
# define initialUsbCheck notify global:INITIALIZED usb create


# If the above notify did not helped, then you probably have to enable some of the following lines.  Verify first that /dev/xxx ist correct.
#define FHZ FHZ /dev/USB0
#define CUL CUL /dev/ttyACM0@9600 1234
#attr CUL rfmode HomeMatic

#define EUL TCM 310 /dev/ttyACM0@57600
#define BscBor TCM 120 /dev/ttyUSB0@9600
#define BscSmartConnect TCM 310 /dev/ttyUSB0@57600
#FB_checkPw does not for FB-OS > 5.22
#attr WEB basicAuth {use FritzBoxUtils;;FB_checkPw("localhost","$password") }
#attr WEBphone basicAuth {use FritzBoxUtils;;FB_checkPw("localhost","$password") }
#attr WEBtablet basicAuth {use FritzBoxUtils;;FB_checkPw("localhost","$password") }
#attr telnetPort globalpassword {use FritzBoxUtils;;FB_checkPw("localhost","$password") }


###START### Initialize HMLAN  ###START###
define HMLAN1 HMLAN 192.168.178.20:1000
attr HMLAN1 hmId 000001
attr HMLAN1 hmLanQlen 1_min
####END#### Initialize HMLAN  ####END####

###START### Initialize ActionDetector to process KeepAlive Signals  ###START###
define ActionDetector CUL_HM 000000
attr ActionDetector actCycle 600
attr ActionDetector event-on-change-reading .*
attr ActionDetector room CUL_HM
define FileLog_ActionDetector FileLog ./log/ActionDetector-%Y.log ActionDetector
attr FileLog_ActionDetector logtype text
attr FileLog_ActionDetector room CUL_HM
####END#### Initialize ActionDetector to process KeepAlive Signals  ####END####



###START### Define Door/Window Sensors ###START###

###START######### BedRoom #########START###
define BR_Window CUL_HM 219A50
attr BR_Window .devInfo 810101
attr BR_Window .stc 80
attr BR_Window actCycle 028:00
attr BR_Window actStatus unknown
attr BR_Window autoReadReg 4_reqStatus
attr BR_Window devStateIcon closed:icoWINDOWmed.closed open:icoWINDOWmed.open
attr BR_Window expert 2_full
attr BR_Window firmware 2.1
attr BR_Window group Windows-Doors
attr BR_Window model HM-SEC-SC
attr BR_Window peerIDs
attr BR_Window room Bedroom
attr BR_Window serialNr GEHEIM234
attr BR_Window subType threeStateSensor
define FileLog_BR_Window FileLog ./log/BR_Window-%Y.log BR_Window
attr FileLog_BR_Window logtype text
attr FileLog_BR_Window room CUL_HM
define Bat_BR_Window notify BR_Window.battery.* {evtHandlerBattery('BR_Window',ReadingsVal("BR_Window", "battery", "default"));;}
####END########## BedRoom ##########END####

####END#### Define Door/Window Sensors ####END####


99_myUtils.pm:
Bemerkung: Man beachte, dass ich die Fallabfrage "if($State !~ m/ok/)" zu Testzwecken auskommentiert habe.
##############################################################################
#                                                                            #
# Filename:    99_myUtils.pm                                                 #
# Last Update: 06.12.2013                                                    #
# Author:      Matthias Deeke                                                #
#                                                                            #
#                                                                            #
#                                                                            #
#                                                                            #
##############################################################################


package main;
use strict;
use warnings;
use POSIX;
use FritzBoxUtils;                                       # Use FritxBoxUtils to get access to FritxBox Tools like mailer



###BEGIN### Define Sub for sending emails ###BEGIN###
sub fb_mail {
my $rcpt = $_[0];
my $subject = $_[1];
my $text = $_[2];
my $sender = "fhem\@mail.de";
my $provider = "smtp.mail.de";
my $user = "fhem\@mail.de";
my $passwrd = "NatuerlichGeheim";

system("/bin/echo \"$text\" > /var/tmp/fhem_nachricht.txt");
system("/sbin/mailer send -i '/var/tmp/fhem_nachricht.txt' -s \"$subject\" -f \"$sender\" -t \"$rcpt\" -m \"$provider\" -a \"$user\" -w \"$passwrd\"");
system("rm /var/tmp/fhem_nachricht.txt");
}
####END#### Define Sub for sending emails ####END####


###BEGIN### Define Sub for sending emails for low Battery notifications ###BEGIN###
sub evtHandlerBattery {

my $Message = "Battery Status for Device ".$_[0].": ".$_[1];

#Commented for test reasons... Do not forget the bracket "{"### if($State !~ m/ok/) {
   {fb_mail('mail@mail.de','FHEM Battery Warning',$Message)};

Log 3, "$_[0]: Battery Status: $_[1]";
}
####END#### Define Sub for sending emails for low Battery notifications ####END####



Vielen Dank fuer Eure Tipps vorweg!

___________________________________________________________
FritzBox 7390 mit FRITZ!OS: 06.00;
fhem letztes update: 05.12.2013;
Homematic LAN Adapter v.0.961;
1xHM-Sec-Sc Schalter;
******************************
Man wird immer besser...

hckoe

Hallo Sailor,

das sollte so funktionieren

trigger BR_Window battery:low


Gruß
Helmut
# CT mit Debian Buster / FHEM aktuell / EnOcean TCM310 / Eltako FSA12, FUD12NPN, FSB12, FRW, FSRP-230V
# Permundo PCS234, Nodon NO-SIN-2-2-00, GTAGS

Sailor

#2
Man bin ich doof!   :o

Danke das wars! - Man triggert das Device (BR_Window), nicht das definierte atrribut (Bat_BR_Window).

Wieder was gelernt!

Gruss
   Sailor
******************************
Man wird immer besser...