Add a dim function to a pushbutton  [Solved]

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

Moderator: leecollings

Post Reply
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Add a dim function to a pushbutton

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Add a dim function to a pushbutton

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

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

Post by dutchronnie »

Thanks Waaren, it works :D
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest