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

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

Moderator: leecollings

Post Reply
diman27
Posts: 6
Joined: Sunday 30 August 2020 16:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Russian
Contact:

Change the brightness with a button (long hold)

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

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
diman27
Posts: 6
Joined: Sunday 30 August 2020 16:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Russian
Contact:

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

Post by diman27 »

Error, not working.
Attachments
2020-09-16_06-36-38.png
2020-09-16_06-36-38.png (35.67 KiB) Viewed 597 times
User avatar
boum
Posts: 135
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest