Determine "who" initiated a RFX command (the "user" that is logged in the device log)

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

Moderator: leecollings

Post Reply
holly
Posts: 3
Joined: Monday 20 November 2017 18:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Determine "who" initiated a RFX command (the "user" that is logged in the device log)

Post by holly »

Hi everybody,

here is what I would like to achieve: when a RFXCOM-based device is switched on, I would like to use the information of who has triggered it within a script.

The device log shows accurately who has switched it on/off in the "user" column: a script, the domotics user interface, a timer, a RFX remote control.

The script I would like to use listens for device changes:

Code: Select all

on = {
	devices = {
	'RFX-CH02'
		}
But is there any chance to handle the "user" who switched? Is it somewhere in the device properties? I did not find it yet.

Thanks for your support - very much appreciated
holly
Posts: 3
Joined: Monday 20 November 2017 18:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Determine "who" initiated a RFX command (the "user" that is logged in the device log)

Post by holly »

...and here is the answer ;-)
Bad weather yesterday allowed for some addtional research.
I found one link that said it is not possible directly and another one that showed how to access the history log of a switch via the Domoticz API.

Both combined is the solution

Code: Select all

return {
	on = {
		devices = {'The Switch'},
		httpResponses = { 'logInfo' },
	},

	execute = function(domoticz, triggeredItem, info)

        if (triggeredItem.isHTTPResponse) then
            if (triggeredItem.ok) then
                local result = domoticz.utils.fromJSON(triggeredItem.data)
                if string.find(result['result'][1]["User"], 'EventSystem') then
                   -- do something when the EventSystem triggered the switch
                end
            end
        end

        if (triggeredItem.isDevice) then
            domoticz.openURL({ url = 'http://<domoticz IP>:<port>/json.htm?idx=' .. triggeredItem.idx .. '&type=lightlog',method = "GET",callback = 'logInfo' })   
	end
	
end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest