Page 1 of 1
How can I stop a Python script from Domoticz?
Posted: Monday 08 May 2017 21:34
by paul402
Following on from "Can I trigger Python Scripts from Domo"! from another poster.
I have integrated my script which directly controls my shutters and other hardware into Domoticz and am able to start the script automatically with an event. Hooray! It took me a while...
But I haven't worked out how to stop the script should it be necessary. I cannot imagine that I need to sudo into Python and find the process ID etc and kill it.
Do I need to have a dummy variable somewhere set by Domoticz and my script somehow checks the value of this variable or is their another easier way?
Re: How can I stop a Python script from Domoticz?
Posted: Tuesday 09 May 2017 6:30
by paul402
In the absence of any replies I set my script to die at "00:00" and an event to start it again at "00:01".
May be this will help someone else with the same issue.
Re: How can I stop a Python script from Domoticz?
Posted: Tuesday 09 May 2017 6:48
by jannl
Why should you want to stop the script. You trigger it from Domoticz, so if it should not run you do mot trigger it? Or am I missing something?
Verstuurd vanaf mijn SM-G930F met Tapatalk
Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 7:06
by paul402
My script is another separate process running 24/7 and I wanted to restart it in the middle of the night which of course I can do with a cron job as well.
The script will happily run standalone (been running over a year now) but I wanted to try and report the status of various variables on the dashboard of Domoticz. I don't need Domoticz but I could use it if it can do what I want.
Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 7:23
by jannl
I think I don't understand what you want. First you say the script is started from an event in domoticz and later you say the the script runs 24/7. Please explain.
Verstuurd vanaf mijn SM-G930F met Tapatalk
Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 7:42
by paul402
Sure. Script currently runs 24/7 unattended and works perfectly without Domoticz. It has sunrise/sunset functionality from PyEphem and I built an interface to Jarolift hardware which I don't think too many people have done as I could find few references on the internet.
IF I want to run it concurrently together with Domoticz I would/could change the functionality slightly.
1. I could re-start the script every midnight or just after under the control of Domoticz just because I can...
2. I could show, I hope, variables/status messages from my process/script on the dashboard.
What Domoticz could do for me is allow me to have internet access without me having to write the code myself. Yes I could do it myself as I have written a few websites but I am getting older and lazy.

Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 11:00
by Westcott
How about if your script sends data to Domoticz once a day?
Or receives once a day?
Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 16:38
by paul402
@Westcott point me in the right direction please
For each shutter 'event' I would like to transfer; device#, time of last command, command(up/down/stop).
So 18 x 3 variables at the moment which is quite a few. I store them all in a NumPy array which is updated on every event and reset at 00:01.
I have read the section on setting up user variables in the database but the rest is a bit vague for me.
Any pointers for "painless" development welcome...
Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 19:04
by Westcott
Hi Paul402,
Just to be clear, you want to create 18 user variables in Domoticz, and update them from your script?
What are your Python programming skills like?
Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 21:52
by paul402
Haha! Wish it was only 18, no at least 54 variables. I want to show 18 graphics, one for each device containing the Label:
ie Lounge-Sliding Door
Device#: 01
Cmd Time: 13:45
Cmd: Open
Python skills are ok, my variables already exist and are running. Every time they are updated, I write out to a file/display on Raspberry. it is placing the variables in Domoticz that I need to learn at the moment.
As for Python I am slowly writing code for a robot sailing boat. Firstly a simulation and then later, may be, the real thing with real hardware. - see here
http://www.microtransat.org/ and much more interesting than programming Domoticz.!
Re: How can I stop a Python script from Domoticz?
Posted: Wednesday 10 May 2017 22:10
by Westcott
Ah, right.
Do you want to see them as dummy devices in Domoticz?
Or do you want just uservariables?
Either way a 'requests' JSON call to Domoticz will update them, one at a time.
You can add devices/variables as well, also with JSON.
Re: How can I stop a Python script from Domoticz?
Posted: Saturday 13 May 2017 21:52
by paul402
After searching through lots of posts because I couldn't find one with everything I needed in one place, I came up with this for my Python file to create a variable but it is not working yet.
Code: Select all
#!/usr/bin/env python3
import requests
import json
#parse URL
httpurl="http://192.168.2.99:8080/json.htm?type=command¶m=saveuservariable&myfirstvar&type=2&vvalue="xxx"
r=requests.get(httpurl)
Code executes from a switch and no error in log but I don't see my new variable in the list.
Other Python scripts execute fine from a switch.
What have I missed?
Re: How can I stop a Python script from Domoticz?
Posted: Saturday 13 May 2017 22:13
by paul402
Found it!!!

a typo as I forgot vname...
Yes! It is working. Yippeeeee
Re: How can I stop a Python script from Domoticz?
Posted: Saturday 13 May 2017 22:25
by paul402
So to finish up with the complete code which might help somebody else
Code: Select all
#!/usr/bin/env python3
import requests
import json
#parse URL
httpurl="http://192.168.2.99:8080/json.htm?type=command¶m=saveuservariable&vname=myfirstvar&type=2&vvalue="xxx"
r=requests.get(httpurl)
print(r)