Page 1 of 1

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

Posted: Sunday 12 December 2021 9:34
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

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

Posted: Monday 13 December 2021 16:08
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
}