I have been trying to run a python script from Domoticz and I can't get it to work. Please forgive me, I am pretty much a total noob to the world of domoticz, python and pi.
I've spent hours looking stuff up on various forums etc.
I'm running domoticz as the pi user on a raspberry pi 3.
I'm trying a very basic python script (example.py) just to try and get it to work. example.py is in the /home/pi/domoticz/scripts folder. This script creates a text file in the scripts folder. I have tested it by running it from the command line (logging in to the Pi via putty) and it works fine.
Code: Select all
#!/usr/bin/python
mylogfile = '/home/pi/domoticz/scripts/example.log'
f = open(mylogfile, 'a')
f.write('Writing Example')
f.close()
I have made this script executable: sudo chmod +x example.py.
I'm trying to get it to run by turning a switch on. I have created a dummy switch and tried adding various strings to the On Action using the full path and a just script... and with 2 and 3 slashes:
The following 2 result in an error in the Domoticz log saying 'error executing script command'
- script://example.py
- script:///home/pi/domoticz/scripts/example.py
The following 2 do not show an error in the log. The log just says Admin initiated a switch command.
- script://home/pi/domoticz/scripts/example.py
- script:///example.py
However, the script does not appear to run as the text file is not created.
I read somewhere that I should created a bash script to call the python script.
I therefore created the following script (callexample.sh) in /home/pi/domoticz/scripts:
Code: Select all
#!/bin/bash
/usr/bin/python /home/pi/domoticz/scripts/example.py
I have made this script executable: sudo chmod +x example.py.
I have tested it using the command line: bash callexample.sh and it works fine. The text file is created.
I have then tried the following strings in the On Action of the dummy switch:
- script:///callexample.sh
- script://home/pi/domoticz/scripts/callexample.sh
As before, there are no errors in the log for either of the above, but the text file is not created.
I've searched for more information as much as possible, but I'm stuck. I suspect it is something to do with permissions and the scripts not being allowed to run, but I don't understand enough about it.
If anyone can help, it would be much appreciated. As I said, I'm very new to all of this, so step by step instructions woud be very helpful.