Page 1 of 1

toggleSwitch method in dzVents behaves slow and unpredictable

Posted: Monday 16 September 2019 20:54
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
}

Re: Can a scene trigger other scenes?

Posted: Monday 16 September 2019 22:34
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 
}