Feature request: asynchronous execution of system shell commands.

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
akamming
Posts: 422
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Feature request: asynchronous execution of system shell commands.

Post by akamming »

I have some scripts to be executed locally (e.g. i use sunspec-monitor to retrieve the actual status of my solaredge inverter with an os.execute command). But i found out sometimes there is a hickup and then the execution takes a lot of time. And everytime this is the case the whole dzvents system awaits the execution of these scripts.

This could be prevented if i could execute these scripts asynchronously: a dzvents script can start the execution of a local command. And if the result is there, this is the new trigger to start a dzvents script. (Just like the asynchronous http handling).

As a workaround i installed lighttpd on my system and create a php script to execute local scripts, so i can use the asynchronous http handling, but this is a very complex way to fix this.

So here 's my suggestion: Would it be possible to add asynchronous execution of shell commands (just like asynchronous http handling) as a feature to dzvents?
User avatar
boum
Posts: 136
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Feature request: asynchronous execution of system shell commands.

Post by boum »

Yup. Some PipeRequest, or CommandRequest API would be nice.

A lighter alternative to run a full server:
  • First, add & to your os.execute command to run in the background.
  • Then you create a dummy text, or switch device.
  • You add/modify your dzVents script to trigger on that device.
  • At the end of your script, you can add a HTTP request to update it. In your script you can get some string or just a state if you just want to know your command is finished:

    Code: Select all

    http://localhost:port/json.htm?type=command&param=udevice&idx=DUMMYIDX&nvalue=0&svalue=DUMMYTEXT
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Feature request: asynchronous execution of system shell commands.

Post by freijn »

Perhaps :

1) end the os command with an & so it does get exe in the background and domo_scripts continue?
if it needs to run when a domo_script is hit, set a file , have the other script looking for the file and have it deleted after exe ? clunky but works :-)
2) fire the script with a cron statment ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Feature request: asynchronous execution of system shell commands.

Post by waaren »

akamming wrote: Friday 13 September 2019 14:50 So here 's my suggestion: Would it be possible to add asynchronous execution of shell commands (just like asynchronous http handling) as a feature to dzVents?
The difficulty here is that the OS command will not report back to domoticz when it is ready.

A workaround would be:
1. As suggested add ' &' to the command to have it execute in the background.
2. Look at this post for a method to retrigger the script after a given time using the httpResponse trigger.
3. Check output of the OS command to see if it has finished.

or

1. As suggested add ' &' to the command to have it execute in the background.
2. Have the OS command / script update a domoticz virtual device or uservar.
3. Have the dzVents triggered based on the virtual device / user var from step 2
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
akamming
Posts: 422
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Feature request: asynchronous execution of system shell commands.

Post by akamming »

freijn wrote: Friday 13 September 2019 16:46 Perhaps :

1) end the os command with an & so it does get exe in the background and domo_scripts continue?
if it needs to run when a domo_script is hit, set a file , have the other script looking for the file and have it deleted after exe ? clunky but works :-)
2) fire the script with a cron statment ?
tx.. i've thought of both (a trigger file and cron), however one of my scripts is calculating actual power consumption, so this would give too much delay.
akamming
Posts: 422
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Feature request: asynchronous execution of system shell commands.

Post by akamming »

waaren wrote: Friday 13 September 2019 21:22 The difficulty here is that the OS command will not report back to domoticz when it is ready.
OK... so my suggestion is not possible unfortunately
waaren wrote: Friday 13 September 2019 21:22 1. As suggested add ' &' to the command to have it execute in the background.
2. Have the OS command / script update a domoticz virtual device or uservar.
3. Have the dzVents triggered based on the virtual device / user var from step 2
This could work. i'll give it a try… tx!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest