How can I stop a Python script from Domoticz?
Moderator: leecollings
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
How can I stop a Python script from Domoticz?
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?
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?
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
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.
May be this will help someone else with the same issue.
-
- Posts: 673
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: How can I stop a Python script from Domoticz?
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
Verstuurd vanaf mijn SM-G930F met Tapatalk
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
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.
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.
-
- Posts: 673
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: How can I stop a Python script from Domoticz?
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
Verstuurd vanaf mijn SM-G930F met Tapatalk
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
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.
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.

- Westcott
- Posts: 423
- Joined: Tuesday 09 December 2014 17:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: UK - Glos
- Contact:
Re: How can I stop a Python script from Domoticz?
How about if your script sends data to Domoticz once a day?
Or receives once a day?
Or receives once a day?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
@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...

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...
- Westcott
- Posts: 423
- Joined: Tuesday 09 December 2014 17:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: UK - Glos
- Contact:
Re: How can I stop a Python script from Domoticz?
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?
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?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
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.!
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.!
- Westcott
- Posts: 423
- Joined: Tuesday 09 December 2014 17:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: UK - Glos
- Contact:
Re: How can I stop a Python script from Domoticz?
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.
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.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
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 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?
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)
Other Python scripts execute fine from a switch.
What have I missed?
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
Found it!!!
a typo as I forgot vname...
Yes! It is working. Yippeeeee

Yes! It is working. Yippeeeee
-
- Posts: 96
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: How can I stop a Python script from Domoticz?
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)
Who is online
Users browsing this forum: No registered users and 1 guest