Page 1 of 1
How to check if group state is mixed?
Posted: Sunday 29 October 2017 20:44
by pj-r
How can I check if group state is 'mixed'?
The domoticz.groups('myGroup').state returns 'Off' even there is one light turned on and UI shows 'mixed'.
Is it possible to get list/table of devices from group?
I'd like to create a rule if any of the lights in one group is on then I wouldnt want to turn on another light with motion sensor.
Re: How to check if group state is mixed?
Posted: Sunday 29 October 2017 21:45
by pj-r
This is what I ended up by now.
Code: Select all
local kitchenLightsGroup = {'Eteinen-spotit',
'Kettio-spotit-vasen',
'Keitto-spotit-oikea',
'Ruokapoyta',
'Saareke katto',
'Allastaso',
'Ylakaapit',
'Ylavalo'}
return {
on = {
devices = {
['Motion-kids'] = {'between 02:00 and 07:00'}
},
timer = {
'every minute between 02:00 and 06:00'
}
},
execute = function(domoticz, device)
--domoticz.log('Keittio: ' .. domoticz.groups('Keittio-valot').state, domoticz.LOG_INFO)
if(s ~= nil) then
-- triggered by motion sensor
-- check what light are already on at kitchen
local enabledkitchenLights = {}
for i, name in ipairs(kitchenLightsGroup) do
if(domoticz.devices(name).state ~= 'Off') then
enabledkitchenLights[#enabledkitchenLights+1] = name
end
end
-- This would be nice if we could take light from group and take all of them what are not off
-- local enabledkitchenLights = kitchenLightsGroup.filter(function (lightName)
-- return (domoticz.devices(lightName).state ~= 'Off')
-- end)
-- Just debugging
for i, lightName in ipairs(enabledkitchenLights) do
domoticz.log('Light on: ' .. lightName , domoticz.LOG_INFO)
end
-- Turn kids room light on with very much dimmed so they can see and walk to parents room at night
if(domoticz.devices('MH1-katto').state == 'Off' and #enabledkitchenLights == 0) then
domoticz.devices('MH1-katto').dimTo(35)
domoticz.log('Turn on kids room night walking light', domoticz.LOG_INFO)
end
elseif(domoticz.devices('MH1-katto').state == 'On' and domoticz.devices('MH1-katto').lastUpdate.minutesAgo > 10) then
-- no motion for a while, turn off kids room light
-- TODO: add check if was turned on by switch
domoticz.devices('MH1-katto').switchOff()
domoticz.log('Turn off kids room night walking light', domoticz.LOG_INFO)
end
end
}
Re: How to check if group state is mixed?
Posted: Monday 30 October 2017 7:21
by dannybloe
Yes, that's because the group by itself is a kind of device that has a state. Its state is not depending on its group members. Don't know how expensive it is to provide the information in dzVents. I'm afraid it requires extra queries that have to be run before dzVents can start processing scripts.
Re: How to check if group state is mixed?
Posted: Monday 30 October 2017 8:41
by pj-r
How expensive would it be to build device-id's list(and perhaps some other group device properties) for group when application is started and refresh it when group(scene) is modified?
Code: Select all
SELECT Scenes.ID AS SceneID, SceneDevices.DeviceRowID AS DeviceID,
SceneDevices.Cmd AS DeviceCommand, SceneDevices.Level AS Level,
SceneDevices.Hue AS Hue, SceneDevices.OnDelay AS OnDelay,
SceneDevices.OffDelay AS OffDelay FROM SceneDevices
INNER JOIN Scenes ON Scenes.ID = SceneDevices.SceneRowID
WHERE Scenes.ID = 4
Bit of the same area:
viewtopic.php?f=59&t=19848