Page 1 of 1

How to switch lights with pushbutton?

Posted: Wednesday 11 December 2019 14:24
by dutchronnie
I have bought a pusbutton from banggood: https://www.banggood.com/KTNNKG-3V-433M ... rehouse=CN

I added the push button in domoticz.
When i push the button it is activated in domotocz, but the pusbutton stays active. When i push again nothing happens
The only way to deactivate the witch is in domoticz, or when i add a delay of 1 second.

Does anybody know how i can use this button to switch a light?

When i add a dzvents script t turn on a light, it works a little.
The lights goes on, but goes off again with the 1 second delay.

I hope somebody can help

Re: How to switch lights with pushbutton?

Posted: Wednesday 11 December 2019 15:46
by waaren
dutchronnie wrote: Wednesday 11 December 2019 14:24 I have bought a pusbutton from banggood
I do not own this type of pushButton but a similar one. Mine is setup in domoticz as a selector type switchwith levelNames
Off, Click, Double Click, Long Click and Long Click Release
To inspect how yours is setup please run below script a couple of times and collect the relevant loglines. Maybe that will help identifying what happens
dutchronnie wrote: Wednesday 11 December 2019 14:24 When i add a dzVents script to turn on a light, it works a little. The lights goes on, but goes off again with the 1 second delay.
Please share the script and relevant loglines so we can try to help you solve the issue.

Code: Select all

return 
{
    on = 
    {
        devices = 
        { 
            'pushButton' -- change to name of your device
        }
    },
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    execute = function(dz, item)
        _G.logMarker =  _G.moduleLabel
        dz.log('State of ' .. item.name .. ' is ' .. ( item.state or 'NA'),dz.LOG_DEBUG)
        dz.log('nValue ' .. item.name .. ' is ' .. ( item.nValue or 'NA'),dz.LOG_DEBUG)
        dz.log('sValue ' .. item.name .. ' is ' .. ( item.sValue or 'NA'),dz.LOG_DEBUG)
        dz.log('type of ' .. item.name .. ' is ' .. ( item.deviceType  or 'NA'),dz.LOG_DEBUG)
        dz.log('subType of ' .. item.name .. ' is ' .. ( item.deviceSubType or 'NA'),dz.LOG_DEBUG)
        dz.log('Level ' .. item.name .. ' is ' .. ( item.level or 'NA' ),dz.LOG_DEBUG)
        dz.log('levelName of ' .. item.name .. ' is ' .. ( item.levelName or 'NA'),dz.LOG_DEBUG)
    end
}

Re: How to switch lights with pushbutton?

Posted: Wednesday 11 December 2019 19:50
by dutchronnie
Thanks Waaren,

This are the results when i push the button:

2019-12-11 19:40:08.936 Status: dzVents: Info: Handling events for: "Drukknop", value: "On"
2019-12-11 19:40:08.936 Status: dzVents: Info: ------ Start internal script: Script #2: Device: "Drukknop (RFLink Gateway)", Index: 241
2019-12-11 19:40:08.936 Status: dzVents: Debug: Script #2: State of Drukknop is On
2019-12-11 19:40:08.936 Status: dzVents: Debug: Script #2: nValue Drukknop is 1
2019-12-11 19:40:08.937 Status: dzVents: Debug: Script #2: sValue Drukknop is On
2019-12-11 19:40:08.937 Status: dzVents: Debug: Script #2: type of Drukknop is Light/Switch
2019-12-11 19:40:08.937 Status: dzVents: Debug: Script #2: subType of Drukknop is EV1527
2019-12-11 19:40:08.937 Status: dzVents: Debug: Script #2: Level Drukknop is 0
2019-12-11 19:40:08.937 Status: dzVents: Debug: Script #2: levelName of Drukknop is NA

All the times i press the button i get the same results.
Long Press, double click, all the same

I have to click in Domoticz on the button to switch it off.

Then i get the following results:

2019-12-11 19:48:07.463 Status: User: Admin initiated a switch command (241/Drukknop/Off)
2019-12-11 19:48:08.109 Status: dzVents: Info: Handling events for: "Drukknop", value: "Off"
2019-12-11 19:48:08.110 Status: dzVents: Info: ------ Start internal script: Script #2: Device: "Drukknop (RFLink Gateway)", Index: 241
2019-12-11 19:48:08.110 Status: dzVents: Debug: Script #2: State of Drukknop is Off
2019-12-11 19:48:08.110 Status: dzVents: Debug: Script #2: nValue Drukknop is 0
2019-12-11 19:48:08.110 Status: dzVents: Debug: Script #2: sValue Drukknop is Off
2019-12-11 19:48:08.110 Status: dzVents: Debug: Script #2: type of Drukknop is Light/Switch
2019-12-11 19:48:08.110 Status: dzVents: Debug: Script #2: subType of Drukknop is EV1527
2019-12-11 19:48:08.110 Status: dzVents: Debug: Script #2: Level Drukknop is 0
2019-12-11 19:48:08.110 Status: dzVents: Debug: Script #2: levelName of Drukknop is NA

The button is not switching off by clicking on the button.

Re: How to switch lights with pushbutton?

Posted: Wednesday 11 December 2019 20:02
by wvries
Hi Ronnie

It is a push on button.
No change he in state only can trigger on activation.

So in either lua or dzvents create a script that has an on active -> toggle the device.
With this you can emulate an on-off switch

Re: How to switch lights with pushbutton?

Posted: Wednesday 11 December 2019 20:36
by waaren
dutchronnie wrote: Wednesday 11 December 2019 19:50 2019-12-11 19:40:08.936 Status: dzVents: Debug: Script #2: State of Drukknop is On
I have to click in Domoticz on the button to switch it off.
The button is not switching off by clicking on the button.
can you try this one ?

Code: Select all

return 
{
    on = { devices =  { 'pushButton' }}, -- change to name of your pushButton

    execute = function(dz)
        dz.devices('lightName').toggleSwitch() -- change to name of your light
    end
}


Re: How to switch lights with pushbutton?

Posted: Wednesday 11 December 2019 20:53
by dutchronnie
Thanks waaren,

This code is doinge exactly what i want.

push button, and the light goes on, push again and the light goes out.

Thanks