Hauptmenü

Python Script

Begonnen von Wolfgang Hochweller, 08 Oktober 2017, 18:00:58

Vorheriges Thema - Nächstes Thema

Wolfgang Hochweller

Ich dachte, ich haette es verstanden, sieht aber nicht so aus.
Ich moechte ein Pythonscript ausfuehren und das Ergebnis weiter verwenden.
Aus einem Terminal :
python /opt/fhem/python/verisure_getAlarm.py

gibt mir das Ergebnis : DISARMED
Sehr schoen !

Aus FHEM heraus :
VerisureAlarm:.* {
my $alarm = qx (python /opt/fhem/python/verisure_getAlarm.py);;
fhem ( "setstate VerisureAlarm $alarm" );;
}

Das qx Kommando weigert sich.

amenomade

Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Wolfgang Hochweller

Vielleicht noch wichtig :
Mein FHEM laeuft jetzt auf Ubuntu.
Vorher hatte ich alles unter Windows und ich meine, da hat das funktioniert.

Das Log zeigt mir folgendes :

  File "/opt/fhem/python/verisure_getAlarm.py", line 1, in <module>
    import verisure
  File "/usr/local/lib/python2.7/dist-packages/verisure/__init__.py", line 13, in <module>
    from .session import ( # NOQA
  File "/usr/local/lib/python2.7/dist-packages/verisure/session.py", line 7, in <module>
    import requests
  File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 97, in <module>
    from . import utils
  File "/usr/local/lib/python2.7/dist-packages/requests/utils.py", line 42, in <module>
    if platform.system() == 'Windows':
  File "/usr/lib/python2.7/platform.py", line 1286, in system
    return uname()[0]
  File "/usr/lib/python2.7/platform.py", line 1253, in uname
    processor = _syscmd_uname('-p','')
  File "/usr/lib/python2.7/platform.py", line 988, in _syscmd_uname
    rc = f.close()
IOError: [Errno 10] No child processes


amenomade

Ich meine die Logfile von Fhem.
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Otto123

#4
Hi,

gib mal bitte ein komplettes list vom notify in code tags -> die # Taste über dem  :-X Smily

Sieht ansonsten eigentlich gut aus -> https://forum.fhem.de/index.php?topic=59291.0

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

Wolfgang Hochweller

Bin etwas unsicher , was ihr meint :
Der Ausschnitt oben ist der Teil des Logfiles, der entsteht, wenn ich das Notify triggere.

Das Notify :


VerisureAlarm:.* {
my $alarm = qx (python /opt/fhem/python/verisure_getAlarm.py);;
fhem ( "setstate VerisureAlarm $alarm" );;
}


Das Pythonscript :



import verisure

session = verisure.Session('user', 'pass')
session.login()
armstate = session.get_arm_state()
session.logout()
print(armstate["statusType"])


andies

Führe mal python innerhalb von FHEM als sudo aus (ich hoffe, das geht), wer weiß, wie da die Rechte gesetzt sind. Also statt
python DeinProgramm.py
besser
sudo python DeinProgramm.py
FHEM 6.3 auf RaspPi4 (Raspbian:  6.6.28+; Perl: v5.36.0)
SIGNALduino (433 MHz) und HM-UART (868 MHz), Sonoff, Blitzwolf, Somfy RTS, CAME-Gartentor, Volkszähler, Keyence-Sensor, Homematic-Sensoren und -thermostat, Ferraris-Zähler für Wasseruhr, Openlink-Nachbau Viessmann

Otto123

ich meine das Ergebnis von list <name des notify> komplett. Das was Du schreibst ist nur die DEF.

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

amenomade

Und die Logfile von FHEM sieht so aus:
2017.10.01 19:16:45 1: PERL WARNING: Terminating on signal SIGINT(2)
2017.10.02 23:40:08 1: starting in console mode
2017.10.02 23:40:08 1: Including fhem.cfg
2017.10.02 23:40:08 3: telnetPort: port 7072 opened
2017.10.02 23:40:09 3: WEB: port 8083 opened
2017.10.02 23:40:09 3: WEBphone: port 8084 opened
2017.10.02 23:40:09 3: WEBtablet: port 8085 opened
2017.10.02 23:40:09 2: eventTypes: loaded 240 events from ./log/eventTypes.txt

Mit Datum, Uhrzeit, Loglevel, usw.
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Wolfgang Hochweller

Hhmmm, Rechte ?
Ja, kann natuerlich sein, habe ich mich nach der Installation nie drum gekuemmert.
Der FHEM-Server laeuft unter dem USER fhem.
Alles, was ich tue, tue ich unter meinem User.
Also, z. B
. die Verisure Routinen sind unter meinem User angelegt, wie auch alles andere, was  sonst so erledigt werden muss.


amenomade

Wegen Rechte, kannst Du einfach { qx(python -c print) } im Kommandofeld von FHEM eingeben. Wenn nix in der Logfile von Fhem (wenn Du die gefunden hast) kommt, dann kannst Du python von fhem aus ausführen. Auch mit dem echten script kannst Du probieren:
{ qx (python /opt/fhem/python/verisure_getAlarm.py);; }

sollte was in der Log oder in der Weboberfläsche ausgeben. Entweder eine Fehlermeldung oder den Wert, den Du willst.
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Wolfgang Hochweller

Das habe ich schon probiert , Ergebnis :
Logfile :

2017.10.08 22:45:55 1: Including fhem.cfg
2017.10.08 22:45:55 3: telnetPort: port 7072 opened
2017.10.08 22:45:55 3: WEB: port 8083 opened
2017.10.08 22:45:55 3: WEBphone: port 8084 opened
2017.10.08 22:45:55 3: WEBtablet: port 8085 opened
2017.10.08 22:45:55 2: eventTypes: loaded 199 events from ./log/eventTypes.txt
2017.10.08 22:45:55 3: Opening RFXTRX device /dev/ttyUSB0
2017.10.08 22:45:55 3: Setting RFXTRX serial parameters to 38400,8,N,1
2017.10.08 22:45:58 1: TRX: Init OK
2017.10.08 22:45:58 1: TRX: Init status: '433.92MHz transceiver, firmware=1020, protocols enabled: Lighting4 FineOffset/Viking Rubicson LaCrosse Hideki OREGON HOMEEASY AC ARC HomeComfort '
2017.10.08 22:45:58 3: RFXTRX device opened
2017.10.08 22:45:58 3: Opening ZWAVE2 device /dev/ttyACM0
2017.10.08 22:45:58 3: Setting ZWAVE2 serial parameters to 38400,8,N,1
2017.10.08 22:45:59 3: ZWAVE2 device opened
2017.10.08 22:45:59 3: FHEM2FHEM opening RemoteServer at 10.0.0.40:7072
2017.10.08 22:46:00 3: TABLETUI: new ext defined infix:ftui/: dir:./www/tablet/:
2017.10.08 22:46:00 3: Registering HTTPSRV TABLETUI for URL /ftui   and assigned link ftui/ ...
2017.10.08 22:46:00 2: SIRD Init module
2017.10.08 22:46:00 1: Including ./log/fhem.save
2017.10.08 22:46:00 2: SecurityCheck:  WEB has no associated allowed device with basicAuth. telnetPort has no associated allowed device with password/globalpassword.  Restart FHEM for a new check if the problem is fixed, or set the global attribute motd to none to supress this message.
2017.10.08 22:46:00 0: Featurelevel: 5.8
2017.10.08 22:46:00 0: Server started with 120 defined entities (fhem.pl:15112/2017-09-21 perl:5.022001 os:linux user:fhem pid:29577)
2017.10.08 22:46:00 3: FHEM2FHEM device opened (RemoteServer)
Traceback (most recent call last):
  File "/opt/fhem/python/verisure_getAlarm.py", line 1, in <module>
    import verisure
  File "/usr/local/lib/python2.7/dist-packages/verisure/__init__.py", line 13, in <module>
    from .session import ( # NOQA
  File "/usr/local/lib/python2.7/dist-packages/verisure/session.py", line 7, in <module>
    import requests
  File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 97, in <module>
    from . import utils
  File "/usr/local/lib/python2.7/dist-packages/requests/utils.py", line 42, in <module>
    if platform.system() == 'Windows':
  File "/usr/lib/python2.7/platform.py", line 1286, in system
    return uname()[0]
  File "/usr/lib/python2.7/platform.py", line 1253, in uname
    processor = _syscmd_uname('-p','')
  File "/usr/lib/python2.7/platform.py", line 988, in _syscmd_uname
    rc = f.close()
IOError: [Errno 10] No child processes
2017.10.08 22:46:17 3: setstate VerisureAlarm  : Usage: setstate <name> <state>
where <name> is a single device name, a list separated by komma (,) or a regexp. See the devspec section in the commandref.html for details.

2017.10.08 22:46:17 3: VAlarm_check return value: Usage: setstate <name> <state>
where <name> is a single device name, a list separated by komma (,) or a regexp. See the devspec section in the commandref.html for details.

Logfile Ende.

Ein Unterschied gibt es natuerlich :
Wenn ich das Kommando im Terminal ausfuehre, dann unter meinem User.
Aus FHEM heraus halt mit dem User fhem.


Otto123

Ich würde sagen es liegt nicht an den Rechten oder der Ausführung von python, es liegt an den Rechten für verisure. Das python script braucht mehr Rechte an irgendwas.
Aber ich habe davon keine Ahnung ...

Viel Erfolg Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

amenomade

#13
Was ergibt { qx(uname -p 2> /dev/null) } im Kommandofeld von FHEM?
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Wolfgang Hochweller

#14
Das gibt :
x86_64

Zur Information :
Die Verisurefunktionen kommen von hier :

https://github.com/persandstrom/python-verisure
Fuer die Benutzung hat man zwei Moeglichkeiten :

Command Line
oder
Module

Letzteres habe ich die ganze Zeit probiert, ohne Erfolg.

Gehe ich ueber Command Line, dann sieht das Notify in etwa so aus :


VerisureAlarm:.* {
my @alarm = qx(vsure "user" "pass"  armstate);;
fhem ( "setstate VerisureAlarm @alarm[2]" );;
}


Das funktioniert, als @alarm bekomme ich folgendes :

    "date": "2017-10-08T12:54:56.000Z",
    "statusType": "DISARMED",
    "name": "Wolfgang Hochweller",
    "changedVia": "TAG",
    "cid": "00767376"

als @alarm[2]   bekomme ich also

"statusType": "DISARMED"

Die Reihenfolge in @alarm ist aber nicht festgelegt,
ich muss also noch das richtige raussuchen, denn haben will ich nur :  DISARMED