doorbell script

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

doorbell script

Post 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!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: doorbell script

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: doorbell script

Post 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
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: doorbell script

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

Re: doorbell script

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: doorbell script

Post by snellejellep »

thank you, it works great!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
mojso
Posts: 92
Joined: Friday 08 November 2019 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: doorbell script

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

Who is online

Users browsing this forum: Google [Bot] and 1 guest