Page 1 of 1

Light switch/Doorbel Modernizer

Posted: Thursday 09 September 2021 18:13
by DRB2019
Hello,

I'am running a script to trigger if the doorbel is pressed, when it's pressed, than
flash some lights for a specific amount of times.
All works wel when they press the doorbel one time, when they press it two time's short after each other (within a sec.)
the light goes on burning constanly and i must switch them off manually.

How to solve this?
Below the script i use.

Code: Select all

return
{
    on = {
         devices = {'Deurbel Modernizr'}
    },

    logging =
    {
        level = domoticz.LOG_ERROR,  -- change to LOG_ERROR when ok (was LOG_DEBUG)
    },
    execute = function(domoticz, item)
        if  item.state == 'On' 
        then
            domoticz.devices('Overkapping').switchOn().forSec(2).repeatAfterSec(1, 8)
        end
    end
}
Running Domoticz
Version: 4.10717
Build Hash: b38b49e5
Compile Date: 2019-05-09 13:04:08
dzVents Version: 2.4.19

Re: Light switch/Doorbel Modernizer

Posted: Thursday 09 September 2021 18:43
by waltervl
Check this topic for some inspiration: viewtopic.php?t=18639

Re: Light switch/Doorbel Modernizer

Posted: Monday 13 September 2021 11:21
by DRB2019
Sorry for the late reply, i wil check the topic.

Re: Light switch/Doorbel Modernizer

Posted: Monday 13 September 2021 13:57
by DRB2019
I solved it in another way.
See the script below.

Code: Select all

  return {
        on = {
            devices = { 'Deurbel Modernizr' }
        },
        data = {
            counter = { initial = 0 }
        },
        execute = function(domoticz, switch)
            if (domoticz.data.counter == 1) then
            domoticz.devices('Overkapping').switchOn().forSec(2).repeatAfterSec(1, 5)
            domoticz.data.counter = 0 -- reset counter
        else
            domoticz.data.counter = domoticz.data.counter + 1
        end
    end
    }

/code]

Re: Light switch/Doorbel Modernizer

Posted: Monday 13 September 2021 14:29
by erem
the way i read your code it will only blink the lights on the 2nd press.
the first press the counter is 0.

just my $.02

Re: Light switch/Doorbel Modernizer

Posted: Monday 13 September 2021 14:32
by DRB2019
It works, i only press the doorbel once....

Re: Light switch/Doorbel Modernizer

Posted: Monday 13 September 2021 15:24
by erem
must be me then....

i think
1st press -> counter = 0 -> counter becomes 1
2nd press -> counter = 1 -> code executes, counter is reset to 0

never mind, if it works it works

Re: Light switch/Doorbel Modernizer

Posted: Saturday 16 October 2021 19:16
by rrozema
You are right erem, it only works when the script gets triggered for a 2nd time. So it doesn't activate when the door bell switches on, it only activates the lights when the doorbell switches back from On to Off.

I think this will work better:

Code: Select all

  return {
        on = {
            devices = { 'Deurbel Modernizr' }
        },
        data = {
            counter = { initial = 0 }
        },
        execute = function(domoticz, switch)
		if switch.active then	-- only when the doorbell switches On, not when it switches Off.
        		domoticz.data.counter = domoticz.data.counter + 1
        		if domoticz.data.counter == 1 then
				domoticz.devices('Overkapping').switchOn().forSec(2).repeatAfterSec(1, 5)
			end
			domoticz.data.counter = domoticz.data.counter - 1
		end
        end
    end
    }
You could also try using toggleSwitch() instead of switchOn(). I'm not sure this will work, but I expect this to switch the light off for a short period if it was on at the time the doorbell was pushed. And switch it on temporarily when it was off. The documentation doesn't mention timed command support for toggleSwitch, but the code in switc_device.lua does seem to support TimedCommand.