dzVents 3.1.0 has been merged in Domoticz V2020.2 build 12771. Thanks to the initial idea and most of the coding done by @akamming, a new-, asynchronous approach to executing shell commands is introduced in this version.
dzVents now allows you to make asynchronous shell commands and handle the results. Asynchronous means that you don't block the system while waiting for the response. Earlier you had to use functions like utils.osCommand() or os.Execute() and some magic to make sure that you didn't block the system for too long after which Domoticz comes with a message that the script took more than 10 seconds.
Now there are two methods to execute a shell command asynchronously, determined by how you use the domoticz.executeShellCommand() command. The simplest form simply calls executeShellCommand on the domoticz object with only the command as the parameter (a string value):
Code: Select all
domoticz.executeShellCommand('some shell command')
The second way is more exiting...
Instead of passing a command you pass in a table with the command to be executed and a callback trigger (a string) and (optional) a timeout (integer)
Code: Select all
return {
on = { ... }, -- some trigger
execute = function(domoticz)
domoticz.executeShellCommand({
command = 'some shell command',
callback = 'mycallbackstring',
timeout = timeoutinseconds, -- defaults to 10 seconds. Set to 0 to disable timeout
})
end
}
Code: Select all
return {
on = {
shellCommandResponses = { 'mycallbackstring' }
},
execute = function(domoticz, response)
if response.ok then
if (response.isJSON) then
domoticz.log(response.json.some.value)
end
else
domoticz.log('There was an error', domoticz.LOG_ERROR)
end
end
}
Code: Select all
return {
on = {
timer = {'every 5 minutes'},
shellCommandResponses = { 'trigger' }
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.executeShellCommand({
command = '...',
callback = 'trigger'
timeout = 0,
})
end
if item.isShellCommandResponse then
if item.statusCode == 0 then
...
end
end
end
}
have Fun !