Light switch/Doorbel Modernizer

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

Moderator: leecollings

Post Reply
User avatar
DRB2019
Posts: 24
Joined: Saturday 06 July 2019 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Light switch/Doorbel Modernizer

Post 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
User avatar
waltervl
Posts: 5846
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Light switch/Doorbel Modernizer

Post by waltervl »

Check this topic for some inspiration: viewtopic.php?t=18639
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
DRB2019
Posts: 24
Joined: Saturday 06 July 2019 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Light switch/Doorbel Modernizer

Post by DRB2019 »

Sorry for the late reply, i wil check the topic.
User avatar
DRB2019
Posts: 24
Joined: Saturday 06 July 2019 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Light switch/Doorbel Modernizer

Post 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]
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Light switch/Doorbel Modernizer

Post 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
Regards,

Rob
User avatar
DRB2019
Posts: 24
Joined: Saturday 06 July 2019 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Light switch/Doorbel Modernizer

Post by DRB2019 »

It works, i only press the doorbel once....
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Light switch/Doorbel Modernizer

Post 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
Regards,

Rob
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Light switch/Doorbel Modernizer

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

Who is online

Users browsing this forum: No registered users and 1 guest