botany wrote: ↑Wednesday 29 January 2020 16:13
is it possible to change dim level manual ?
and if there is movement. lights stay on same level as i put it manually?
because sometimes its nice to change the dim level depending on the situation .
Yes that is possible. My approach would be to use a virtual dimmer as override that sets the dimlevel of the devices in the group to the same level as the virtual dimmer and use that same virtual dimmer as override if it is not 'Off' or has dimlevel 0.
Something like
Code: Select all
return
{
on =
{
devices =
{
'PIR',
'virtualDimmer',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to error when script is tested and OK
marker = conditionalDimmer,
},
execute = function(dz, item)
local Lux = dz.devices('Lux')
local dimmerGroup = dz.groups('dimGroup')
local override = dz.devices('virtualDimmer')
local dimTimeTable = { -- [ 'timeSlot' ] = { [measuredLux] = dimLevel
['at 00:01-08:00'] = {
[200] = 2,
[300] = 6,
[500] = 9,
},
['at 08:01-12:00'] = {
[300] = 20,
[500] = 40,
[900] = 60,
},
['at 12:01-23:00'] = {
[800] = 30,
[1200] = 60,
[3000] = 90,
},
['at 23:01-24:00'] = {
[0] = 15
},
}
function getDimlevelBasedOnLux(t, measuredLux)
local delta = 999999
local keyDimLevel = 1
for key, dimLevel in pairs(t) do
if math.abs(measuredLux - key) < delta then
delta = math.abs(measuredLux - key)
keyDimLevel = key
end
end
return t[keyDimLevel]
end
function dimDevicesInGroup(groupName,dimValue)
dz.groups(groupName).devices().forEach(function(device)
device.cancelQueuedCommands()
device.dimTo(dimValue)
dz.log(device.name .. ' switched On (dimlevel: ' .. dimValue .. ')',dz.LOG_DEBUG)
end)
end
function switchOffDevicesInGroup(groupName,delay)
dz.groups(groupName).devices().forEach(function(device)
device.switchOff().afterSec(delay)
dz.log(device.name .. ' will be switched Off after ' .. delay .. ' seconds.',dz.LOG_DEBUG)
end)
end
if item.switchType == 'Dimmer' then
if item.state ~= 'Off' then
dimDevicesInGroup(dimmerGroup.name, item.level)
else
dimDevicesInGroup(dimmerGroup.name, 0)
end
elseif item.state ~= 'On' and override.state ~= 'Off' then
switchOffDevicesInGroup(dimmerGroup.name,60)
dz.log('Lights in ' .. dimmerGroup.name .. ' will be switched Off after one minute',dz.LOG_DEBUG)
elseif override.state ~= 'Off' then
for timeSlot, luxLevels in pairs (dimTimeTable) do
if dz.time.matchesRule(timeSlot) then
local dimValue = getDimlevelBasedOnLux(luxLevels, Lux.lux )
dz.log( 'Devices in ' .. dimmerGroup.name .. ' will be switched On (dimlevel: ' .. dimValue ..
'); Based on: timeslot ('.. timeSlot .. '), measured Lux (' .. Lux.lux ..')',dz.LOG_DEBUG)
dimDevicesInGroup(dimmerGroup.name,dimValue)
return false
end
end
else
dz.log('Groupdim level is overrided by ' .. override.name .. ' and fixed at level ' .. override.level ,dz.LOG_DEBUG)
end
end
}
(not tested)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki