Page 1 of 1
Modify DZ Vents
Posted: Saturday 20 July 2019 1:52
by alarm_guy1
Hi Guys,
I have for me an excellent DZ Vents Script created for me, it runs nearly every light in the house, however I could do with some assistance to tweak it a bit.
I'm going to add a door sensor to my bathroom door and would like to have it set like so:
if detector picks you up and the door remains open continue as normal
if the door is closed regardless of the detector state, lights to come on indefinately until door is opened but @20%
and after 23:30 just come on @1% as it is now
Many Thanks
Re: Modify DZ Vents
Posted: Saturday 20 July 2019 1:54
by alarm_guy1
Forgot to attach code
Code: Select all
return {
on = {
devices = {
"Bathroom MD Burglar",
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "Bathroom Motion"
},
execute = function(dz, item)
local function logWrite(str,level)
dz.log(str,level or dz.LOG_DEBUG)
end
-- local Lux = dz.devices("Kitchen MD Lux").lux
local LuxDevice = dz.devices(177) -- <<<--- replace xxx by IDX of your Lux device
local Lux = LuxDevice.lux
-- local Lights = dz.devices("Bathroom Dimmer Level")
local Lights = dz.devices(68) -- <<<--- replace xxx by IDX of your Bathroom lights
logWrite(LuxDevice.name .. " ==>> Lux: " .. Lux )
logWrite(Lights.name .. " ==>> State: " .. Lights.state)
logWrite(item.name .. " ==>> State: " .. item.state)
if Lux < 1020 and item.state == "On" then
Lights.cancelQueuedCommands()
if dz.time.matchesRule("at 23:30-06:00") then
Lights.dimTo(01)
else
Lights.dimTo(90)
end
elseif item.state == "Off" and Lights.state == "On" then
Lights.switchOff().afterSec(300)
end
end
}
Cheers
Re: Modify DZ Vents
Posted: Saturday 20 July 2019 11:55
by waaren
alarm_guy1 wrote: Saturday 20 July 2019 1:52
I'm going to add a door sensor to my bathroom door and would like to have it set like so:
if detector picks you up and the door remains open continue as normal
if the door is closed regardless of the detector state, lights to come on indefinately until door is opened but @20%
and after 23:30 just come on @1% as it is now
If my interpretation of your requirements is correct it could look like
Code: Select all
local bathroomSensor = "Bathroom MD Burglar"
local bathroomDoor = "Bathroom door"
return
{
on =
{
devices =
{
bathroomSensor,
bathroomDoor,
},
timer =
{
"every 5 minutes between 23:30 and 06:00",
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = "Bathroom Motion"
},
execute = function(dz, item)
local function logWrite(str,level)
dz.log(str,level or dz.LOG_DEBUG)
end
local door = dz.devices(bathroomDoor)
local sensor = dz.devices(bathroomSensor)
-- local Lux = dz.devices("Kitchen MD Lux").lux
local LuxDevice = dz.devices(177) -- <<<--- replace xxx by IDX of your Lux device
local Lux = LuxDevice.lux
-- local Lights = dz.devices("Bathroom Dimmer Level")
local Lights = dz.devices(68) -- <<<--- replace xxx by IDX of your Bathroom lights
logWrite(LuxDevice.name .. " ==>> Lux: " .. Lux )
logWrite(Lights.name .. " ==>> State: " .. Lights.state)
logWrite(door.name .. " ==>> State: " .. door.state)
logWrite(sensor.name .. " ==>> State: " .. sensor.state)
local function timeConditionalDimmer(wake, sleep)
if not wake then wake = 90 end
if not sleep then sleep = 1 end
Lights.cancelQueuedCommands()
if dz.time.matchesRule("at 23:30-06:00") then
Lights.dimTo(sleep)
else
Lights.dimTo(wake)
end
end
if item.isTimer then
if ( door.state == "Closed" ) and ( door.lastUpdate.secondsAgo > 300 ) and ( sensor.lastUpdate.secondsAgo > 300 ) then
timeConditionalDimmer()
end
elseif Lux < 1020 and sensor.state == "On" then
timeConditionalDimmer()
elseif door.state == "Closed" then
timeConditionalDimmer(20)
elseif sensor.state == "Off" and Lights.state == "On" and door.state == "Open" then
Lights.switchOff().afterSec(300)
end
end
}
Re: Modify DZ Vents [Solved]
Posted: Saturday 20 July 2019 12:19
by alarm_guy1
Cool cheers.
Im just in the process of adding the contact to my alarm system then I will implement this code.
It wont be for a week or so as I never expected such a swift response.
Many many thanks.
I will let you know how it goes
cheers