Page 1 of 1

Change the brightness with a button (long hold)

Posted: Tuesday 15 September 2020 17:27
by diman27
Hello to all. Help how to make a change in brightness by holding the button. We hold the button and the brightness decreases, release it, press it, hold it and the brightness increases.

Code: Select all

return {
    on = {
        devices = {
            'зал у дивана',
        }
    },

    execute = function(domoticz, device)
        local Wand = domoticz.devices('Зал 1')

        domoticz.log('Устройство ' .. device.name .. ' был изменен. Статус: ' .. Wand.level, domoticz.LOG_INFO)

        Wand.cancelQueuedCommands()

        elseif device.levelName == "Long Click" then
            for dimLevel = 1, 100 do
                Wand.dimTo(dimLevel).afterSec(dimLevel / 10)
            end
        end

    end
}
I'm sorry for my bad english

Re: Change the brightness with a button (long hold)  [Solved]

Posted: Tuesday 15 September 2020 20:55
by waaren
diman27 wrote: Tuesday 15 September 2020 17:27 Hello to all. Help how to make a change in brightness by holding the button. We hold the button and the brightness decreases, release it, press it, hold it and the brightness increases.
Could be something like

Code: Select all

return
{
    on =
    {
        devices =
        {
            'зал у дивана',
        },
    },

    data =
    {
        direction =
        {
            initial = 'up',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'brightness',
    },

    execute = function(domoticz, device)
        local Wand = domoticz.devices('Зал 1')

        domoticz.log('Устройство ' .. device.name .. ' был изменен. Статус: ' .. Wand.level, domoticz.LOG_DEBUG)

        Wand.cancelQueuedCommands()

        if device.levelName == "Long Click" then
            if dz.data.direction == 'up' then
                dz.data.direction = 'down'
                for dimLevel = Wand.level , 100 do
                    Wand.dimTo(dimLevel).afterSec( ( dimLevel - Wand.level ) / 10)
                end
            else
                dz.data.direction = 'up'
                for dimLevel = Wand.level , 0, -1 do
                    Wand.dimTo(dimLevel).afterSec( ( Wand.level - dimLevel  ) / 10)
                end
            end
        end

    end
}

Re: Change the brightness with a button (long hold)

Posted: Wednesday 16 September 2020 1:39
by diman27
Error, not working.

Re: Change the brightness with a button (long hold)

Posted: Wednesday 16 September 2020 9:31
by boum
Please, check what you are copying in the script editor. You are missing the first 4 lines of the script. No wonder there is an error.
diman27 wrote: Wednesday 16 September 2020 1:39 Error, not working.