Seite 1 von 2

Rule vs. Bash

Verfasst: 5. Nov 2021 10:39
von merlindata
Hallo!
Da es für meine Klimaanlage (Panasonic Comfort Cloud) kein Binding gibt möchte ich ein Phyton Script verwenden das ich gefunden habe.
Dieses läst sich auch mittels Direktaufruf im Bash (obenhabian) ausführen und funktioniert.

Code: Alles auswählen

python3 /etc/openhab/scripts/airconditioner.py status 
Jedoch als Rule funktioniert es nicht.

Code: Alles auswählen

rule "AirCon Manual Status Update"
when
	Item Aircon_Update changed to ON
then
	executeCommandLine(Duration.ofSeconds(20), "python3", "/etc/openhab/scripts/airconditioner.py", "Status");
        logInfo("INFO","Aircon Start")
end
Info: openhabian 3.1.0 - Release Build, Pi4 (4GB)

Ich habe gefühlt schon das ganze Internet durchsucht, aber es will und will nicht, es kommt auch keinen Error usw. im log!

Vielen Dank im Vorraus, Merlin

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 11:08
von peter-pan
wie wär's mit einem "kleinen" status ? In der Regel steht ein "grosser" Status

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 11:29
von merlindata
Hallo Peter,
habs geändert. PI neu gestartet aber brachte leider keinene Erfolg.

Danke und LG, Merlin

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 11:57
von Tokamak
Vermutlich wirst du den Pfad zu python3 mit angeben müssen, also /usr/bin/python3.

Wenn das nicht funktioniert, würde ich ohne lange zu forschen ein Script /etc/openhab/scripts/airconditioner.sh mit

Code: Alles auswählen

#!/bin/sh
/usr/bin/python3 /etc/openhab/scripts/airconditioner.py status
schreiben und das mittels

Code: Alles auswählen

executeCommandLine(Duration.ofSeconds(20), "/etc/openhab/scripts/airconditioner.sh");
starten.

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 13:11
von peter-pan
Hat "openhab" das Recht das Script auszuführen ? Ist das Script in der whitelist ?

Hast du es mal so probiert:

Code: Alles auswählen

sudo -u openhab python3 /etc/openhab/scripts/airconditioner.py status

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 13:44
von merlindata
Nach eingabe von

Code: Alles auswählen

sudo -u openhab python3 /etc/openhab/scripts/airconditioner.py status
ist folgende Meldung im Log:

Code: Alles auswählen

openhabian@openhabian:~ $ sudo -u openhab python3 /etc/openhab/scripts/airconditioner.py status
Traceback (most recent call last):
  File "/etc/openhab/scripts/airconditioner.py", line 3, in <module>
    import pcomfortcloud
ModuleNotFoundError: No module named 'pcomfortcloud'
Meine exec.whitelist

Code: Alles auswählen

# For security reasons all commands that are used by the exec binding or transformation need to be whitelisted.
# Every command needs to be listed on a separate line below.
sudo %2$s
sudo /bin/systemctl %2$s openhab2.service
python3 /etc/openhab/scripts/airconditioner.py status
sudo python3 /etc/openhab/scripts/airconditioner.py status

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 14:12
von peter-pan
Bitte vergiss, was ich gerade geschrieben habe. Ich denke @Tokamak hat Recht. ich habe mich gerade mal an einem kleinen Script versucht:

Code: Alles auswählen

import sys
print (sys.argv[0]) # prints python script name
print (sys.argv[1]) # prints var1
print (sys.argv[2]) # prints var2
print (sys.argv[3]) # prints var3

print("Hallo Welt")
der Aufruf in der DSL-Rule:

Code: Alles auswählen

    pingresult = executeCommandLine(Duration.ofSeconds(20),"python3","/etc/openhab/scripts/hello.py", "status","python","script")  // String in einer Variablen zwischenspeichern
    logInfo("execute-Version 7","String - pingresult: {}", pingresult)                             // Log  pingresult
Ausgabe im Log:

Code: Alles auswählen

2021-11-05 14:00:59.721 [INFO ] [.core.model.script.execute-Version 7] - String - pingresult: /etc/openhab/scripts/hello.py
status
python
script
Hallo Welt
Klappt ohne Fehler.

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 14:22
von peter-pan

Code: Alles auswählen

ModuleNotFoundError: No module named 'pcomfortcloud'
Könnte das der Fehler sein ? Evtl. hat "openhab" keine Berechtigung für dieses Modul bzw. für diesen Ordner ? Oder findet ihn nicht (Pfad)

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 14:55
von merlindata
Ich habe leider keine Ahnung von python, das Modul ist aber scheinbar installiert!?

Code: Alles auswählen

openhabian@openhabian:~ $ python3 -m pip install --upgrade pcomfortcloud

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pcomfortcloud in ./.local/lib/python3.7/site-packages (0.0.22)
Requirement already satisfied: requests>=2.20.0 in /usr/lib/python3/dist-packages (from pcomfortcloud) (2.21.0)

Re: Rule vs. Bash

Verfasst: 5. Nov 2021 21:05
von peter-pan
merlindata hat geschrieben: 5. Nov 2021 14:55 Ich habe leider keine Ahnung von python, das Modul ist aber scheinbar installiert!?
...da sind wir ja schon zwei.

Vielleicht kann @udo1toni weiterhelfen ?