Page 1 of 1

Add a dim function to a pushbutton

Posted: Friday 10 April 2020 9:44
by dutchronnie
I have a script that was working fine, but i want that the light is dimming to 100%

This was the original code

Code: Select all

return 
{
    on = { devices =  { 'Drukknop keuken' }}, -- Name of your pushButton

    execute = function(dz)
        dz.devices('Keuken Koof').toggleSwitch()  -- Name of your light
        dz.devices('Keuken Nis').toggleSwitch()    -- Name of your light
    end
}
So i changed the script to:

Code: Select all

return 
{
    on = { devices =  { 'Drukknop keuken' }}, -- Name of your pushButton

    execute = function(dz)
        dz.devices('Keuken Koof').toggleSwitch().dimTo(100)   -- Name of your light
        dz.devices('Keuken Nis').toggleSwitch()    			 -- Name of your light
    end
}
This is not working, i get the following error in the log:

6: attempt to call a nil value (field 'dimTo')

Does somebody know what i am doing wrong?

Re: Add a dim function to a pushbutton

Posted: Friday 10 April 2020 10:08
by waaren
dutchronnie wrote: Friday 10 April 2020 9:44 I have a script that was working fine, but i want that the light is dimming to 100%
Does somebody know what i am doing wrong?
You try to combine the methods toggleSwitch() and dimTo()
dzVents cannot determine where to toggle to so this combination is not valid.

Try with this implementation of a 'home made' toggle function

Code: Select all

return 
{
    on = 
    { 
        devices =  
        { 
            'Drukknop keuken'  -- Name of your pushButton
        }
    }, 

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'toggle on pushbutton',
    },
    
    execute = function(dz)
        local koof = dz.devices('Keuken Koof')
        local nis = dz.devices('Keuken Nis')
        
        if koof.active then 
            koof.dimTo(0)
        else
            koof.dimTo(100)
        end    
        nis.toggleSwitch()
    end
}

Re: Add a dim function to a pushbutton  [Solved]

Posted: Friday 10 April 2020 10:40
by dutchronnie
Thanks Waaren, it works :D