toggleSwitch method in dzVents behaves slow and unpredictable

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

Moderator: leecollings

Post Reply
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

toggleSwitch method in dzVents behaves slow and unpredictable

Post by Gravityz »

@waaren.

tried to change my bash script to a dzvents version but it seems dzvents is way slower.
because of that not al the Hue lights i want to toggle switch either on or off

do you also have this experience.

old setup
scene which fires a bash script which toggles hue lights
curl -s "http://192.168.1.xx:xxxx/json.htm?type=command&param=switchlight&idx=xx&switchcmd=Toggle"
this line 5 times to toggle 5 lights
very fast execution

new setup
scene or pulse switch which triggers dzvents script
very slow, not all lights switch on/off (please note these are hue lights)

Code: Select all

return {

   on = { devices = { "S2 1 click" }},        -- Name of your button
               
   execute = function(dz, item )
         --item.state == "Click" then
            dz.devices("Dressoirlamp").toggleSwitch()    -- Name of your light
            dz.devices("Dressoirlamptoog").toggleSwitch()    -- Name of your light
            dz.devices("Bamboelampklok").toggleSwitch()    -- Name of your light
            dz.devices("Bamboelamphoek").toggleSwitch()    -- Name of your light
            dz.devices("LampachterTV").toggleSwitch()    -- Name of your light
        --end
   end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Can a scene trigger other scenes?

Post by waaren »

Gravityz wrote: Monday 16 September 2019 20:54 tried to change my bash script to a dzvents version but it seems dzvents is way slower.
because of that not al the Hue lights i want to toggle switch either on or off
do you also have this experience.
@Gravityz,

I tested this and see the same behavior. The issue is that sometimes the Hue lights do not make it to the state 'On' when switched but return the state 'set Color' and dzVents will not toggle that state because it can be 'On' or ''Off' and therefore ignore the command.
Have to study the domoticz source code to find if there could be a better way to deal with that at the dzVents runtime level.
Until then the following script will do a much better job. It does not use the toggleSwitch method but the much simpler switchOn / switchOff.

{EDIT} if you change line 159 in <domoticz dir>/dzVents/runtime/device-adapters/Adapters.lua
from

Code: Select all

		['set color'] = { b = true }, 
to

Code: Select all

		['set color'] = { b = true , inv = 'Off'},
the toggleSwitch() method will work the same as the curl command.

Code: Select all

return 
{
    on = { devices = { 'myTrigger' }},

    execute = function(dz )
        -- dzVents 1.247 seconds from start of script to all lights toggled (Raspberry PI-3b debian buster)
        -- bash 0.888 seconds from start to end of script with Curl commands (toggle) (same system)
        
        myHueDevices = { 156, 158, 159 , 161, 160}
        
        for key, idx in ipairs(myHueDevices) do
            dv = dz.devices(idx)
            if dv.state ~= 'Off' then
                dv.switchOff()
            else
                dv.switchOn()
            end
        end 
     end 
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest