dzVents 3.1.0 released

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

Moderator: leecollings

Post Reply
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

dzVents 3.1.0 released

Post by waaren »

All current and future dzVents users,

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')
Domoticz will execute the shell command in a separate thread without blocking anything.

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
}
In this case, Domoticz will execute the command and when done it will trigger an event. dzVents can capture that event and its attributes and will execute all scripts listening for this callback trigger (*mycallbackstring*):

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
}
Of course you can combine the request and response actions in one script:

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
}
Check out this Wiki chapter for detailed descriptions on the request and response API for this new feature including all attributes available


have Fun !
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
heggink
Posts: 977
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: dzVents 3.1.0 released

Post by heggink »

VERY nice! Many thanks!

Sent from my SM-G980F using Tapatalk

Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: dzVents 3.1.0 released

Post by djdevil »

Fabulous! Thanks for your work!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest