Event not triggered  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
dzdm
Posts: 12
Joined: Monday 05 February 2018 14:24
Target OS: Linux
Domoticz version:
Contact:

Event not triggered

Post by dzdm »

Hi all,

I have a group LivingRoom which consists of multiple devices. These devices are controlled via MQTT and included
in domoticz. The problem is, that I want to trigger a special function after the state of the group LivingRoom has changed,
so I tried to use the following trigger:

Code: Select all

on = {
    groups = {
      'LivingRoom'
    }
},
execute = function(dz, item, triggerInfo)
    dz.log('Triggered', dz.PRIORITY_LOW)
end
This does not work though, the trigger is not executed when switching on (or off) the devices via MQTT (also the
state of the LivingRoom group (On or Off) is correctly displayed in the domoticz web ui). Everything works when
switching on or off the group directly via domoticz, in this case the event is triggered.

I'm currently using a workaround - just using the on handler for a specific device of the group, but this is
not really perfect.

Any ideas?

Thanks :)
Last edited by dannybloe on Thursday 08 February 2018 7:36, edited 1 time in total.
Reason: code block
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Event not triggered

Post by dannybloe »

Yes, that indeed doesn't work. I wonder if that's always desirable what you suggest as some people only want to know if the group goes on or off and react upon that.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event not triggered

Post by JanvdW »

@dannybloe, I try to trigger a script when a group goes on or off to react upon that. But that doesn't work. It works if I switch the group manually in Domoticz, but if the status changes (also in the Domoticz application!) because of all group devices change to on or off nothing happens. Ay idea how I can solve that? Or a workaround? How did you solve it @dzdm?
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event not triggered

Post by JanvdW »

Just saw that the group status in Domoticz changes, but it appears that the group log shows only the manual status events. The other status changes (based on status changes of the group members) are not listed.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Event not triggered  [Solved]

Post by waaren »

JanvdW wrote: Saturday 11 January 2020 16:08 Just saw that the group status in Domoticz changes, but it appears that the group log shows only the manual status events. The other status changes (based on status changes of the group members) are not listed.
Only triggering a group / scene event when a group / scene is directly updated and not when the individual group / scene devices change state was a domoticz design decision and that will not be changed.
Imagine the situation where a group state is switched. All devices in that group will change state leading to 1 or more groups / scenes changing state that all would need to trigger an event causing a waterfall of events.
If you need such a scenario you could try to use something like below.

Code: Select all

local myGroup = 'groupTest'

return 
{
	on = 
    {
		groups = 
        {
			myGroup,
		},
        
        devices = 
        { 
            '*',          -- or a wildcarded list like '*_groupTest' or 23,24,25,26 or 'device1', 'device2', 'device3', etc.. 
        },
  	},
	

    logging =   
    {
        level = domoticz.LOG_ERROR,
        marker = 'groupTest', 
    },

	execute = function(dz, item)
        local myGroup = dz.groups(myGroup)
        
        if item.isDevice then
            groupDevice = myGroup.devices().find(function(dv)
                return dv == item
            end) 
        else
            dz.log('Triggered by group ' .. item.name .. '; state = ' .. item.state, dz.LOG_FORCE)
            return
        end

        if groupDevice then  
            dz.log('Triggered by ' .. item.name .. ' (part of '  ..  myGroup.name .. ')' ..
                   '; State of ' .. myGroup.name .. ' is now ' .. myGroup.state, dz.LOG_FORCE)
        else
            dz.log('Item ' .. item.name .. ' is not in group ' .. myGroup.name, dz.LOG_FORCE)
        end
	end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Event not triggered

Post by JanvdW »

All right, understood. I have implemented the alternative solution. Thanks for your response!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest