Find activation Device of Group  [Solved]

Easy to use, 100% Lua-based event scripting framework.
Post Reply
jannnfe
Posts: 32
Joined: Tuesday 30 January 2018 1:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:

Find activation Device of Group

Post by jannnfe » 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:

Code: Select all

local deadDevices = domoticz.groups(item.name).devices().forEach(function(device)
                     return device.name
              end)
         print(deadDevices)
Thanks! :)
Last edited by jannnfe on Friday 14 September 2018 23:40, edited 1 time in total.

User avatar
waaren
Posts: 1209
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Find trigger Device of Group

Post by waaren » Friday 14 September 2018 17:45

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...

Code: Select all

 domoticz.groups(item.name).devices().forEach(function(device) -- loop over all devices in group
                print ("Checking: " .. device.name .. " ; state: " .. device.state)
            end)
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

jannnfe
Posts: 32
Joined: Tuesday 30 January 2018 1:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:

Re: Find trigger Device of Group

Post by jannnfe » Friday 14 September 2018 23:22

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:

Code: Select all

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
}
Thanks :)

User avatar
waaren
Posts: 1209
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Find trigger Device of Group

Post by waaren » Saturday 15 September 2018 0:54

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"

Code: Select all

return {
    on = {
        groups = {
            'Fensterkontakte'
        }
    },
    
    logging =   { 
                    level           = domoticz.LOG_DEBUG, 
                    marker          = "groupStateChange" 
                }, 
    
    execute = function(domoticz, item)
        domoticz.groups(item.name).devices().forEach(function(device)
            dz.log("Checking: " .. device.name .. " ; state: " .. device.state,dz.LOG_DEBUG)
        end)
    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
waaren
Posts: 1209
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Find trigger Device of Group

Post by waaren » Saturday 15 September 2018 2:02

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.

Code: Select all

return {
    on = {
        groups = {
            'Fensterkontakte'
        }
    },
    
    logging =   { 
                    level           = domoticz.LOG_DEBUG, 
                    marker          = "groupStateChange" 
                }, 
    
    execute = function(domoticz, item)
        local secondsAgo = 100
        local activator
        domoticz.groups(item.name).devices().forEach(function(device)
            domoticz.log("Checking: " .. device.name .. " ; state: " .. device.state .. " lastUpdated: " .. device.lastUpdate.secondsAgo,domoticz.LOG_DEBUG)
            if device.lastUpdate.secondsAgo < secondsAgo then
               activator = device.idx 
            end   
        end)
        domoticz.log("Activator is " .. domoticz.device(activator).name ,domoticz.LOG_DEBUG)
        
    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
waaren
Posts: 1209
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Find trigger Device of Group

Post by waaren » Saturday 15 September 2018 12:20

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.

Code: Select all

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&param=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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

jannnfe
Posts: 32
Joined: Tuesday 30 January 2018 1:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:

Re: Find activation Device of Group

Post by jannnfe » Sunday 16 September 2018 10:56

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?

User avatar
waaren
Posts: 1209
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Find activation Device of Group

Post by waaren » Sunday 16 September 2018 15:29


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

Verstuurd vanaf mijn ONEPLUS A3003 met Tapatalk

Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

jannnfe
Posts: 32
Joined: Tuesday 30 January 2018 1:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:

Re: Find activation Device of Group  [Solved]

Post by jannnfe » Sunday 16 September 2018 21:23

Hello, thank you, I have got it right now with persistent data. I added the following:

Code: Select all

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
    
Thank you! :)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests