Page 1 of 1

Feature request: asynchronous execution of system shell commands.

Posted: Friday 13 September 2019 14:50
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?

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

Posted: Friday 13 September 2019 15:27
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

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

Posted: Friday 13 September 2019 16:46
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 ?

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

Posted: Friday 13 September 2019 21:22
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

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

Posted: Saturday 14 September 2019 7:23
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.

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

Posted: Saturday 14 September 2019 7:28
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!