Newbie Question - Can I trigger Python Scripts from Domoticz

Python and python framework

Moderator: leecollings

course66
Posts: 28
Joined: Monday 10 August 2015 23:51
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3202
Location: Italy
Contact:

Re: Newbie Question - Can I trigger Python Scripts from Domo

Post by course66 »

Hi,

among the arguments of the on/off action scripts I would like to include the value of a certain sensor or the status of a certain switch: is it possibile?

thanks and ciao,
gabriele
velkrosmaak
Posts: 8
Joined: Friday 15 April 2016 23:45
Target OS: Linux
Domoticz version:
Contact:

Re: Newbie Question - Can I trigger Python Scripts from Domoticz

Post by velkrosmaak »

Digging up an old thread here, but I have the same issue running on the latest Domoticz release.

I am trying to run a python script from a dummy switch, but when I try, the python script doesn't appear to execute. I added some logging so it writes to a file when it runs, and no dice.

I then made a bash script, which also writes to a different log file when it runs. this bash script simply runs the python script. When I SSH into my Domoticz box and run either the python, or the .sh script - they run fine. When I try it from Domoticz, the bash script runs (as per the logging) but the python script doesn't. Any ideas? Feels like something obvious I'm overlooking. Thanks!
trixwood

Re: Newbie Question - Can I trigger Python Scripts from Domoticz

Post by trixwood »

Make sure the user permissions are correct!

I do not know how you run domoticz, but if it runs as a other user it maybe could not access your script..

Make sure you have:

Code: Select all

#!/usr/bin/python
at the beginning of your python script....
and atleast run

Code: Select all

chmod +x /path/script.py
to make it executable.....
gavacac
Posts: 12
Joined: Tuesday 06 December 2016 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Newbie Question - Can I trigger Python Scripts from Domoticz

Post by gavacac »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest