Hello,
is there a way to get the name of the trigger of a group. There are several devices in a group. One of these is activated, which in turn activates the whole group. But now I want to find out which device has activated the group.
Tried to get the whole devices in group but nothing happend:
jannnfe wrote: ↑Friday 14 September 2018 13:45
Hello,
is there a way to get the name of the trigger of a group. There are several devices in a group. One of these is activated, which in turn activates the whole group. But now I want to find out which device has activated the group.
Tried to get the whole devices in group but nothing happend:
@jannnfe, when I test and activate one or some of the devices in a group, it does not activate the dzVents script with the on = groups section even when domoticz does show a status change. the script is only triggered when the group itself is turned "Off"or "On" Is that working differently at your installation or do I misinterpret your post?
if item is the group for where you want to look at the devices...
Hey @waaren,
thanks for your reply.
I have a group "window contacts". This group contains all window contacts in my house as activation devices for the group.
So, if one of the activation devices in the group is activated, the group will also be activated automatically. That should actually be so by default.
And now I want to use dzVents to determine which activation device the group has activated.
I have extended your approach to test it. Although not exactly what I want to achieve but that does not work. Nothing is output in the log:
return {
on = {
groups = {
'Fensterkontakte'
}
},
execute = function(domoticz, item)
if(item.isGroup) then
if(item.active) then
if(item.name == 'Fensterkontakte') then
domoticz.groups(item.name).devices().forEach(function(device)
print ("Checking: " .. device.name .. " ; state: " .. device.state)
end)
end
end
end
end
}
jannnfe wrote: ↑Friday 14 September 2018 23:22
I have a group "window contacts". This group contains all window contacts in my house as activation devices for the group.
So, if one of the activation devices in the group is activated, the group will also be activated automatically. That should actually be so by default.
And now I want to use dzVents to determine which activation device the group has activated.
I have extended your approach to test it. Although not exactly what I want to achieve but that does not work. Nothing is output in the log:
Please test script below to verify the observation I have with my domoticz systems, On my systems this script is not triggered if the group state is changed by one or more device changes but only when the group is directly switched "On" or "Off"
jannnfe wrote: ↑Friday 14 September 2018 23:22
I have a group "window contacts". This group contains all window contacts in my house as activation devices for the group.
So, if one of the activation devices in the group is activated, the group will also be activated automatically. That should actually be so by default.
And now I want to use dzVents to determine which activation device the group has activated.
Digged a little deeper and hope I understand what your situation is better now. Assuming you have entered the window contacts both as group activators and as group members the following script will give you the name of the window contact that activated the group.
jannnfe wrote: ↑Friday 14 September 2018 23:22
I have a group "window contacts". This group contains all window contacts in my house as activation devices for the group.
So, if one of the activation devices in the group is activated, the group will also be activated automatically. That should actually be so by default.
And now I want to use dzVents to determine which activation device the group has activated.
(I think) Improved version that only looks at the activation devices.
return {
on = {
groups = { 'Fensterkontakte' },
httpResponses = { "getsceneactivations" }},
logging = {
level = domoticz.LOG_DEBUG,
marker = "groupStateChange"
},
execute = function(dz, item)
local function triggerJSON()
local urlString = dz.settings['Domoticz url'] .. "/json.htm?type=command¶m=getsceneactivations&idx=" .. item.idx
dz.openURL({ url = urlString,
method = "GET",
callback = "getsceneactivations" })
end
local function getActivator()
if item.json.result ~= nil then
rt = item.json.result
else
dz.log("No values found",dz.LOG_DEBUG )
return
end
local secondsAgo = 10
local activator = 0
for i=1,#rt do -- Loop through the result
dz.log( "Checking device " .. rt[i].idx .. " ===>> " .. dz.devices(rt[i].idx).name ,dz.LOG_DEBUG)
if dz.devices(rt[i].idx).lastUpdate.secondsAgo < secondsAgo then
activator = rt[i].idx
end
end
if activator == 0 then
dz.log("No activator found ",dz.LOG_DEBUG)
else
dz.log("The group activator is probably device " .. activator .. " (".. dz.devices(activator).name .. ")",dz.LOG_DEBUG)
end
end
if item.isGroup then
triggerJSON()
else
getActivator()
end
end
}
Hello @waaren,
Thank you! That was exactly what I was looking for. Thank you very much for your help, I really appreciate that
EDIT: One last thing. I have already tried a bit but found no solution. How do I get the group name in which the activator is additionally in the getActivator function?
jannnfe wrote:
.. How do I get the group name in which the activator is additionally in the getActivator function?
In its current form the group name is not known to the script when it reaches the getActivator step.
So either use the groupname in a var and use that var in the on = section as groups trigger and somewhere in the getActivator function..(easiest)
Or store the item.name in dzVents persistent data
Please let me know if you cannot get it to work. In that case I will have a look later this week
on = {
...
},
data = {
'groupName'
}
execute = function(domoticz, item)
function getActivator()
local activeGroup = domoticz.data.groupName
end
if(item.isGroup) then
domoticz.data.groupName = item.name
end