Hi,
I want to control an I/O pin on my raspberry with the exec 2.x binding. I have a python script on-off.py , which works:
import RPi.GPIO as GPIO
import sys
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
if len(sys.argv) > 1:
MOTOR_GPIO = 4
GPIO.setup(MOTOR_GPIO, GPIO.OUT)
if sys.argv[1] == "ON":
GPIO.output(MOTOR_GPIO, GPIO.HIGH)
elif sys.argv[1] == "OFF":
GPIO.output(MOTOR_GPIO, GPIO.LOW)
My home.sidemap is:
sitemap home label="Motoren"
{
Frame label="Motor" {
Switch item=MOTOR_1_SWITCH
}
}
My home.item is :
String MOTOR_1_SWITCH "Motor 1" ["Switchable"] { channel="exec:command:motor_1_control:input", channel="exec:command:motor_1_status:output", autoupdate="false" }
My home.things is:
Thing exec:command:motor_1_control [ command="/etc/openhab2/scripts/on-off.py %2$s", interval=0, autorun=true ]
Thing exec:command:motor_1_status [ command="/etc/openhab2/scripts/on-off.py status", interval=60, timeout=5 ]
And my home.rules are:
rule "Motor Power"
when
Item Motor1 changed
then
if(Motor1.state==ON){
Motor1Input.sendCommand("OFF")
}else{
Motor1Input.sendCommand("ON")
}
while(Motor1.state != OFF){
Thread::sleep(500)
}
Motor1.sendCommand(ON)
Zustand.postUpdate(Motor1Output.state.toString)
end
When openhab starts, I get this event.log:
2018-03-12 16:04:25.193 [.ItemChannelLinkAddedEvent] - Link ‘MOTOR_1_SWITCH-exec:command:motor_1_status:output’ has been added.
2018-03-12 16:04:25.198 [.ItemChannelLinkAddedEvent] - Link ‘MOTOR_1_SWITCH-exec:command:motor_1_control:input’ has been added.
2018-03-12 16:04:25.351 [hingStatusInfoChangedEvent] - ‘exec:command:motor_1_control’ changed from UNINITIALIZED to INITIALIZING
2018-03-12 16:04:25.367 [hingStatusInfoChangedEvent] - ‘exec:command:motor_1_control’ changed from INITIALIZING to ONLINE
2018-03-12 16:04:25.370 [hingStatusInfoChangedEvent] - ‘exec:command:motor_1_status’ changed from UNINITIALIZED to INITIALIZING
2018-03-12 16:04:25.379 [hingStatusInfoChangedEvent] - ‘exec:command:motor_1_status’ changed from INITIALIZING to ONLINE
2018-03-12 16:04:25.509 [vent.ItemStateChangedEvent] - MOTOR_1_SWITCH changed from NULL to /etc/openhab2/scripts/on-off.py: 1: /etc/openhab2/scripts/on-off.py: import: not found
/etc/openhab2/scripts/on-off.py: 2: /etc/openhab2/scripts/on-off.py: import: not found
/etc/openhab2/scripts/on-off.py: 3: /etc/openhab2/scripts/on-off.py: Syntax error: word unexpected (expecting “)”)
/etc/openhab2/scripts/on-off.py: 1: /etc/openhab2/scripts/on-off.py: import: not found
/etc/openhab2/scripts/on-off.py: 2: /etc/openhab2/scripts/on-off.py: import: not found
/etc/openhab2/scripts/on-off.py: 3: /etc/openhab2/scripts/on-off.py: Syntax error: word unexpected (expecting “)”)
Does this mean, the python script isn’t ok? As I wrote already, it works from the commandline.
Greetings
Kaloschke