Page 1 of 1

DzVents script for bathroom lights

Posted: Wednesday 06 June 2018 20:11
by snellejellep
Dear all,

i started using dzvents and it is really nice once you get the logic in your head, i created a script which would turn on my bathroom lights (Group badkamer boven = the name in the script) when my motion sensor(PIR badkamer boven = the name in the script) is triggered or when there is water in the shower(Water douche boven = the name in the script). it works well but i had something in my blockly which i was using before where i could check the lux value of my motionsensor and act upon it, also i had time values for example before 23:00 set light to 100% after 23:00 set light at 40% but only if the shower is off. and this all if the lux value was below 30
while i think dzvents would be a much better solution then my 4 combined blockly scripts which stopped magically working i can not seem to find out from the documentation or the awesome getting started video how to get the above functions in my script. so if someone can help me, please... also, do not laugh at my basic level of dzvents plz XD

Code: Select all

return {
	on = {
		devices = {
			'Water douche boven',
			'PIR badkamer boven',
			'licht tk was aan'
		}
	},
	execute = function(domoticz, device)
		if(device.state == 'On') then
		    local badkamer = domoticz.devices('Group badkamer boven').dimTo(100)
		    badkamer.switchOn()
		else
		    local badkamer = domoticz.devices('Group badkamer boven')
		    badkamer.switchOff()
		end
	end
}

Re: DzVents script for bathroom lights

Posted: Wednesday 06 June 2018 23:52
by waaren
Could be something like this:

Code: Select all

--[[ ShowerTest.lua for 
]]--

return {
    on = {
        devices = {
            "Water douche boven",                
            "PIR badkamer boven",
            "licht tk was aan",
        }
    },

    execute = function(dz, device)
    
        local luxLevel      = dz.devices("motion sensor").lux
        local shower        = dz.devices("water douche boven").state
        local badkamerLicht = dz.devices("Group badkamer boven")
        
        local lightStrength = 100
        if (dz.time.matchesRule("at 23:00-23:59") or dz.time.matchesRule("at 00:00-08:00")) and shower.state == "Off"  and luxLevel < 30 then 
            lightStrength = 40
        end
    
        if(device.state == "On") then
            badkamerLicht.dimTo(lightStrength)
        else
            badkamerLicht.switchOff()
        end
    end
}

Re: DzVents script for bathroom lights

Posted: Thursday 07 June 2018 8:10
by snellejellep
wow, thanks again!
this is an amazing start, now i just have to figure out how to let the lights stay on for two minutes or something like that when motion was triggered because that hue motion sensor is really sensitive, when you stand still it immediately stops saying that there is motion and flickering lights are a bit anoying :)
but this is really amazing, i hope you did not only help me but also others who are searching for something similar

Re: DzVents script for bathroom lights

Posted: Thursday 07 June 2018 8:59
by waaren
snellejellep wrote: Thursday 07 June 2018 8:10
.. now i just have to figure out how to let the lights stay on for two minutes or something like that when motion was triggered because that hue motion sensor is really sensitive, when you stand still it immediately stops saying that there is motion and flickering lights are a bit anoying :)
but this is really amazing, i hope you did not only help me but also others who are searching for something similar..
To give an idea how to solve this; added a minimum of 2 minutes between switch "On" and - "Off"
Spoiler: show

Code: Select all

--[[ ShowerTest.lua 
]]--

return {
    on = {
        devices = {
            "Water douche boven",
            "PIR badkamer boven",
            "licht tk was aan"
        }
    },
    
        
    logging =   {   level     =   domoticz.LOG_DEBUG,
                    marker    =   "ShowerTest" },
    

    execute = function(dz, trigger)
    
        local luxLevel      = dz.devices("motion sensor").lux
        local shower        = dz.devices("water douche boven").state
        local badkamerLicht = dz.devices("Group badkamer boven")
        
        local lightStrength = 100
        if (dz.time.matchesRule("at 23:00-23:59") or dz.time.matchesRule("at 00:00-08:00")) and shower.state == "Off"  and luxLevel < 30 then 
            lightStrength = 40
        end
    
    
        if trigger.state == "On"  then 
            if badkamerLicht.level ~= lightStrength then 
                badkamerLicht.dimTo(lightStrength) 
            end
        elseif badkamerLicht.lastUpdate.minutesAgo > 2 then
            badkamerLicht.switchOff()
        else
            dz.log("No action now. " .. badkamerLicht.name .. 
                " switched to \"" .. badkamerLicht.state .. 
                "\" " .. badkamerLicht.lastUpdate.secondsAgo .. 
                " seconds ago.",dz.LOG_DEBUG)    
        end
    end
}

Re: DzVents script for bathroom lights

Posted: Thursday 07 June 2018 19:46
by snellejellep
waaren wrote: Thursday 07 June 2018 8:59
To give an idea how to solve this; added a minimum of 2 minutes between switch "On" and - "Off"
Spoiler: show
wow, amazing! cant thank you enough!

Re: DzVents script for bathroom lights

Posted: Saturday 09 June 2018 11:44
by bozidar
Hi snellejellep
?
Still new to domoticz wondering how do domoticz know shower is on

Re: DzVents script for bathroom lights

Posted: Monday 11 June 2018 21:11
by snellejellep
@bozidar, i use a xiaomi gateway with water sensor, those sensors are really small and fit in the thingy the water flows to (drain?)
links:
gateway: https://www.gearbest.com/living-applian ... id=1433363
sensor: https://www.gearbest.com/home-smart-imp ... id=1433363
other compatible stuff: https://www.domoticz.com/wiki/Compatibl ... n_gearbest

Re: DzVents script for bathroom lights

Posted: Monday 25 June 2018 22:10
by rrozema
waaren wrote: Thursday 07 June 2018 8:59
snellejellep wrote: Thursday 07 June 2018 8:10
.. now i just have to figure out how to let the lights stay on for two minutes or something like that when motion was triggered because that hue motion sensor is really sensitive, when you stand still it immediately stops saying that there is motion and flickering lights are a bit anoying :)
but this is really amazing, i hope you did not only help me but also others who are searching for something similar..
To give an idea how to solve this; added a minimum of 2 minutes between switch "On" and - "Off"
Spoiler: show

Code: Select all

--[[ ShowerTest.lua 
]]--

return {
    on = {
        devices = {
            "Water douche boven",
            "PIR badkamer boven",
            "licht tk was aan"
        }
    },
    
        
    logging =   {   level     =   domoticz.LOG_DEBUG,
                    marker    =   "ShowerTest" },
    

    execute = function(dz, trigger)
    
        local luxLevel      = dz.devices("motion sensor").lux
        local shower        = dz.devices("water douche boven").state
        local badkamerLicht = dz.devices("Group badkamer boven")
        
        local lightStrength = 100
        if (dz.time.matchesRule("at 23:00-23:59") or dz.time.matchesRule("at 00:00-08:00")) and shower.state == "Off"  and luxLevel < 30 then 
            lightStrength = 40
        end
    
    
        if trigger.state == "On"  then 
            if badkamerLicht.level ~= lightStrength then 
                badkamerLicht.dimTo(lightStrength) 
            end
        elseif badkamerLicht.lastUpdate.minutesAgo > 2 then
            badkamerLicht.switchOff()
        else
            dz.log("No action now. " .. badkamerLicht.name .. 
                " switched to \"" .. badkamerLicht.state .. 
                "\" " .. badkamerLicht.lastUpdate.secondsAgo .. 
                " seconds ago.",dz.LOG_DEBUG)    
        end
    end
}
Since this script is only triggered by 3 device triggers, how do you make it so that

Code: Select all

elseif badkamerLicht.lastUpdate.minutesAgo > 2 then
gets executed at some time > 2 minutes after the light is no longer on?

Re: DzVents script for bathroom lights

Posted: Monday 25 June 2018 22:25
by snellejellep
rrozema wrote:
waaren wrote: Thursday 07 June 2018 8:59
snellejellep wrote: Thursday 07 June 2018 8:10
.. now i just have to figure out how to let the lights stay on for two minutes or something like that when motion was triggered because that hue motion sensor is really sensitive, when you stand still it immediately stops saying that there is motion and flickering lights are a bit anoying :)
but this is really amazing, i hope you did not only help me but also others who are searching for something similar..
To give an idea how to solve this; added a minimum of 2 minutes between switch "On" and - "Off"
Spoiler: show

Code: Select all

--[[ ShowerTest.lua 
]]--

return {
    on = {
        devices = {
            "Water douche boven",
            "PIR badkamer boven",
            "licht tk was aan"
        }
    },
    
        
    logging =   {   level     =   domoticz.LOG_DEBUG,
                    marker    =   "ShowerTest" },
    

    execute = function(dz, trigger)
    
        local luxLevel      = dz.devices("motion sensor").lux
        local shower        = dz.devices("water douche boven").state
        local badkamerLicht = dz.devices("Group badkamer boven")
        
        local lightStrength = 100
        if (dz.time.matchesRule("at 23:00-23:59") or dz.time.matchesRule("at 00:00-08:00")) and shower.state == "Off"  and luxLevel < 30 then 
            lightStrength = 40
        end
    
    
        if trigger.state == "On"  then 
            if badkamerLicht.level ~= lightStrength then 
                badkamerLicht.dimTo(lightStrength) 
            end
        elseif badkamerLicht.lastUpdate.minutesAgo > 2 then
            badkamerLicht.switchOff()
        else
            dz.log("No action now. " .. badkamerLicht.name .. 
                " switched to \"" .. badkamerLicht.state .. 
                "\" " .. badkamerLicht.lastUpdate.secondsAgo .. 
                " seconds ago.",dz.LOG_DEBUG)    
        end
    end
}
Since this script is only triggered by 3 device triggers, how do you make it so that

Code: Select all

elseif badkamerLicht.lastUpdate.minutesAgo > 2 then
gets executed at some time > 2 minutes after the light is no longer on?
I ran in to that problem myself so i added a five minute timer as an extra trigger. So it gets triggered every five minutes to check if the lights still need to be on

Re: DzVents script for bathroom lights

Posted: Tuesday 26 June 2018 4:54
by rrozema
ah, thanks. I was wondering if I had overlooked something :-) I have a separate, generic script called "Auto Off" that gets executed once a minute to check for devices that need to be switched off. This way I can keep the scripts to switch things on simple.

Re: DzVents script for bathroom lights

Posted: Wednesday 27 June 2018 14:21
by rogzon
In the off event for the PIR you could put domoticz.devices('bathroom lights name').switchOff().afterMin(2) which would switch off lights two minutes after PIR has reported no motion. You then need to put domoticz.devices('bathroom lights name').cancelQueuedCommands() in PIR On event otherwise it will switch off no matter if PIR has detected motion or not.

Re: DzVents script for bathroom lights

Posted: Sunday 19 August 2018 22:04
by pvm
snellejellep wrote:@bozidar, i use a xiaomi gateway with water sensor, those sensors are really small and fit in the thingy the water flows to (drain?)
Brilliant idea, thnx! Nice solution for switching ventilation