Page 1 of 1

doorbell script

Posted: Monday 10 September 2018 21:20
by snellejellep
dear forum users,

i have a wish and i do not know how to realize it, i have a button connected to domoticz which i want to use as a doorbell, when the doorbell is pressed i want some lights to flash, but is there a possibility to store the state of the light, activate a doorbell scene and after the scene restore the state off the lights.

for as far as i know this should be possible in dzvents but i do not know how to do that.

i hope someone can help me, thanks in advance!

Re: doorbell script

Posted: Monday 10 September 2018 21:29
by waaren
snellejellep wrote: Monday 10 September 2018 21:20 i have a wish and i do not know how to realize it, i have a button connected to domoticz which i want to use as a doorbell, when the doorbell is pressed i want some lights to flash, but is there a possibility to store the state of the light, activate a doorbell scene and after the scene restore the state off the lights.
@snellejellep, Should be possible but some questions:
- are these standard on/off, -dimlights or rgbw type of lights
- howto "flash" these lights? Simple on/off or something else ?

Re: doorbell script

Posted: Monday 10 September 2018 21:40
by snellejellep
waaren wrote:
snellejellep wrote: Monday 10 September 2018 21:20 i have a wish and i do not know how to realize it, i have a button connected to domoticz which i want to use as a doorbell, when the doorbell is pressed i want some lights to flash, but is there a possibility to store the state of the light, activate a doorbell scene and after the scene restore the state off the lights.
@snellejellep, Should be possible but some questions:
- are these standard on/off, -dimlights or rgbw type of lights
- howto "flash" these lights? Simple on/off or something else ?
I use philips hue lights, some are rgb, some just white, i tought about just flashing the white ones and letting the rgb ones flash red, the color change is what makes it difficult i think.
Also i wanted to use the data from my motion sensors to let the lights flash only in the rooms people are

But first wanted to start with just the flashing

Re: doorbell script

Posted: Monday 10 September 2018 22:37
by HansieNL
Maybe you can take a look at the HUE API. https://www.developers.meethue.com/docu ... ng-started
With a curl command a lot is possible:

Code: Select all

curl -H "Accept: application/json" -X PUT --data '{"alert":"select"}' http://<hue-bridge-ip>/api/<hue-username>/lights/4/state

Re: doorbell script

Posted: Tuesday 11 September 2018 1:02
by waaren
snellejellep wrote: Monday 10 September 2018 21:40
waaren wrote:
snellejellep wrote: Monday 10 September 2018 21:20 i have a wish and i do not know how to realize it, i have a button connected to domoticz which i want to use as a doorbell, when the doorbell is pressed i want some lights to flash, but is there a possibility to store the state of the light, activate a doorbell scene and after the scene restore the state off the lights.
@snellejellep, Should be possible but some questions:
- are these standard on/off, -dimlights or rgbw type of lights
- howto "flash" these lights? Simple on/off or something else ?
I use philips hue lights, some are rgb, some just white, i tought about just flashing the white ones and letting the rgb ones flash red, the color change is what makes it difficult i think.
Also i wanted to use the data from my motion sensors to let the lights flash only in the rooms people are

But first wanted to start with just the flashing
Maybe this example script will help in what you want to achieve. Another line of approach could be to trigger an IFTTT applet from this dzVents script.

Code: Select all

-- doorbell actions
 
return {
    on = { devices = {"Doorbell" } },
    
    logging =   {       level   =   domoticz.LOG_DEBUG,                  -- switch to LOG_INFO when results are OK 
                        marker  =   "doorbell actions" },                                           

    execute = function(dz, trigger)
     
        if trigger.state == "Off" then -- No action needed when doorbell switch back to Off state
            return
        end
        
        local rgbwLights    = {"Hue lightstrip","Hue Go","Hue rgbw1","Hue etc"}        -- table with rgbwlights that need to flash red
        local whiteLights   = {"lamp1","lamp2","lamp999"}                             -- table with white lights that need to flash
        
        local function flashRGBWLights()    
            local redflashDelay = 20 		-- delay in seconds
            for i = 1,#rgbwLights do  		-- walk the table from first (1) to last (#rgbwLights)
                local loopDevice = dz.devices(rgbwLights[i])
                local colorTable = dz.utils.fromJSON(loopDevice.color) 
                
                dz.log(loopDevice.name .. " ;state ===>> " .. loopDevice.state,dz.LOG_DEBUG)
                loopDevice.setRGB(255,0,0)                                                  -- Turn to RED
                loopDevice.switchOn()
                loopDevice.setRGB(colorTable.r, colorTable.g, colorTable.b).afterSec(redflashDelay)
                if loopDevice.state == "Off" then
                    dz.log("Schedule switchOff for " .. loopDevice.name,dz.LOG_DEBUG)
                    loopDevice.switchOff().afterSec(redflashDelay)
                end
            end
        end
        
        local function flashWhiteLights()    
            local whiteflashDelay = 1 -- delay in seconds
            for i = 1,#whiteLights do -- walk the table
                local loopDevice = dz.devices(whiteLights[i])
                local state      = loopDevice.state 
                dz.log(loopDevice.name .. " ;state ===>> " .. loopDevice.state,dz.LOG_DEBUG)
                if loopDevice.state == "Off" then
                    loopDevice.switchOn()
                    loopDevice.switchOff().afterSec(whiteflashDelay)
                else
                    loopDevice.switchOff()
                    loopDevice.switchOn().afterSec(whiteflashDelay)
                end
            end
        end
        
        flashRGBWLights()
        flashWhiteLights()

        end
}

Re: doorbell script

Posted: Tuesday 11 September 2018 19:24
by snellejellep
thank you, it works great!

Re: doorbell script

Posted: Monday 06 November 2023 23:34
by mojso
waaren wrote: Tuesday 11 September 2018 1:02
snellejellep wrote: Monday 10 September 2018 21:40
waaren wrote:
@snellejellep, Should be possible but some questions:
- are these standard on/off, -dimlights or rgbw type of lights
- howto "flash" these lights? Simple on/off or something else ?
I use philips hue lights, some are rgb, some just white, i tought about just flashing the white ones and letting the rgb ones flash red, the color change is what makes it difficult i think.
Also i wanted to use the data from my motion sensors to let the lights flash only in the rooms people are

But first wanted to start with just the flashing
Maybe this example script will help in what you want to achieve. Another line of approach could be to trigger an IFTTT applet from this dzVents script.

Code: Select all

-- doorbell actions
 
return {
    on = { devices = {"Doorbell" } },
    
    logging =   {       level   =   domoticz.LOG_DEBUG,                  -- switch to LOG_INFO when results are OK 
                        marker  =   "doorbell actions" },                                           

    execute = function(dz, trigger)
     
        if trigger.state == "Off" then -- No action needed when doorbell switch back to Off state
            return
        end
        
        local rgbwLights    = {"Hue lightstrip","Hue Go","Hue rgbw1","Hue etc"}        -- table with rgbwlights that need to flash red
        local whiteLights   = {"lamp1","lamp2","lamp999"}                             -- table with white lights that need to flash
        
        local function flashRGBWLights()    
            local redflashDelay = 20 		-- delay in seconds
            for i = 1,#rgbwLights do  		-- walk the table from first (1) to last (#rgbwLights)
                local loopDevice = dz.devices(rgbwLights[i])
                local colorTable = dz.utils.fromJSON(loopDevice.color) 
                
                dz.log(loopDevice.name .. " ;state ===>> " .. loopDevice.state,dz.LOG_DEBUG)
                loopDevice.setRGB(255,0,0)                                                  -- Turn to RED
                loopDevice.switchOn()
                loopDevice.setRGB(colorTable.r, colorTable.g, colorTable.b).afterSec(redflashDelay)
                if loopDevice.state == "Off" then
                    dz.log("Schedule switchOff for " .. loopDevice.name,dz.LOG_DEBUG)
                    loopDevice.switchOff().afterSec(redflashDelay)
                end
            end
        end
        
        local function flashWhiteLights()    
            local whiteflashDelay = 1 -- delay in seconds
            for i = 1,#whiteLights do -- walk the table
                local loopDevice = dz.devices(whiteLights[i])
                local state      = loopDevice.state 
                dz.log(loopDevice.name .. " ;state ===>> " .. loopDevice.state,dz.LOG_DEBUG)
                if loopDevice.state == "Off" then
                    loopDevice.switchOn()
                    loopDevice.switchOff().afterSec(whiteflashDelay)
                else
                    loopDevice.switchOff()
                    loopDevice.switchOn().afterSec(whiteflashDelay)
                end
            end
        end
        
        flashRGBWLights()
        flashWhiteLights()

        end
}

the script works great but the brightness stays at 100 percent, can it be returned to the preset brightness of the rgb lights