If you click on the Log button of a switch you see the following table:
In this case the User is = EventSystem/home/pi/domoticz/dzVents/runtime/dzVents.lua
How can I read the User in dzVents? I only need to know the last user who changed the state of the switch.Get user who changed the state of a switch [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Get user who changed the state of a switch
This feature is not completely implemented in domoticz yet. It is something that needs to picked up but might take some time.wizzard72 wrote: ↑Monday 16 March 2020 22:34 If you click on the Log button of a switch you see the following table:
TextLog.png
How can I read the User in dzVents? I only need to know the last user who changed the state of the switch.
In this case the User is = EventSystem/home/pi/domoticz/dzVents/runtime/dzVents.lua
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 116
- Joined: Friday 20 December 2013 7:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Get user who changed the state of a switch [Solved]
Thanks for the information.
-
- Posts: 10
- Joined: Sunday 24 January 2021 20:37
- Target OS: Linux
- Domoticz version:
- Location: Czech Republic
- Contact:
Re: Get user who changed the state of a switch
Hello, any updates please?
Get username of last change could be pretty good to block changes by dzvents for a hour after user exceptional change...
Or is it possible detect that last change of device was not performed by dzvents?
Get username of last change could be pretty good to block changes by dzvents for a hour after user exceptional change...
Or is it possible detect that last change of device was not performed by dzvents?
-
- Posts: 649
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Get user who changed the state of a switch
You could launch a SQL query from DZvents on the lightinglog table to get the user.
For an example how to run a sql query from dzvents you can look in this thread:
viewtopic.php?t=39074
For an example how to run a sql query from dzvents you can look in this thread:
viewtopic.php?t=39074
-
- Posts: 10
- Joined: Sunday 24 January 2021 20:37
- Target OS: Linux
- Domoticz version:
- Location: Czech Republic
- Contact:
Re: Get user who changed the state of a switch
Hello willemd, thanks a lot for hint.
Here is my snap of code - wait 60 minutes after user change...

Here is my snap of code - wait 60 minutes after user change...
Code: Select all
local command = 'sqlite3 /path/to/domoticz.db \"SELECT User, Date FROM LightingLog WHERE DeviceRowID = 145 ORDER BY Date DESC LIMIT 1\" ' -- 145 is IDX of device
local handle = assert(io.popen(command))
for line in handle:lines() do
-- domoticz.log(line, domoticz.LOG_INFO)
i = 0
user = ""
date = ""
for col in string.gmatch(line, "([^|]+)") do
if (i == 0) then -- User
user = col
elseif (i == 1) then -- Date
date = col
end
i = i + 1
end
logDate = Time(date)
if (string.match(user, "dzVents.lua") ~= "dzVents.lua" and logDate.minutesAgo < 60) then
-- some stuff....
return 1
end
end
handle:close()
-
- Posts: 4
- Joined: Tuesday 15 September 2015 13:31
- Target OS: Windows
- Domoticz version:
- Location: Belgium
- Contact:
Re: Get user who changed the state of a switch
Hi,
thanks for posting your findings to get the "action user" via a database query, is exactly what I was searching for.
I tried it out on my Windows system, but I cannot get it working.
I suppose it has something to with the reference of the domoticz.db location(windows is not linux) and tried out different things.
see below my code snippet(= not all the code for reading/focus convenience)
in this code I changed "/path/to/domoticz.db" in below listed flavours to define the right domoticz.db location in window:
Any idea how to reference the right windows location in above salite3 command or what I'm doing wronghere?
thanks for posting your findings to get the "action user" via a database query, is exactly what I was searching for.
I tried it out on my Windows system, but I cannot get it working.
I suppose it has something to with the reference of the domoticz.db location(windows is not linux) and tried out different things.
see below my code snippet(= not all the code for reading/focus convenience)
Code: Select all
[...]
execute = function(domoticz, triggeredItem, info)
print("Script-getActionUser:sprint launched 1")
local command = 'sqlite3 /path/to/domoticz.db \"SELECT User FROM LightingLog WHERE DeviceRowID = 364 ORDER BY Date DESC LIMIT 1\" ' -- 145 is IDX of device
local handle = assert(io.popen(command))
for line in handle:lines() do
print("Script-getActionUser:sprint launched 3")
[...]
- used the real windows path to the domoticz.db file -> "C:/ProgramData/Domoticz/domoticz.db" where I changed all the "\" to the linux variant "/" otherwise the command is not accepted which results in "C:/Users/Frank/Downloads/Domoticz.db"
- I removed the disk reference "C" -> "ProgramData/Domoticz/domoticz.db" -> s
- I made even a Domoticz.db file copy to the default windows home folder(\user\username) -> "User/Frank/Domoticz.db"
- added the disk reference to home location -> "C:/User/Frank/Domoticz.db" ->
- removed complete home path since the home level holds directly the DB file -> "/Domoticz.db or Domoticz.db" ->
Any idea how to reference the right windows location in above salite3 command or what I'm doing wronghere?
-
- Posts: 649
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Get user who changed the state of a switch
Step by step try to find where the error is.
First test whether you can type the command from the commandline and see whether it opens de domoticz.db and executes the query. Once that is confirmed you can continue with the dzvents script.
After you have assigned the line to the local command variable in the script just write that variable to the log file to check whether it is formed correctly.
Once you have assigned the "local handle" also print that variable to the log file, or use dumptable or other commands if it is not a string. Just to see exactly what you are getting back.
Pay special attention to the / and \. In Dzvents the \ is a special character to make sure he next character is not interpreted as special but just taken as-is. for example the ".
First test whether you can type the command from the commandline and see whether it opens de domoticz.db and executes the query. Once that is confirmed you can continue with the dzvents script.
After you have assigned the line to the local command variable in the script just write that variable to the log file to check whether it is formed correctly.
Once you have assigned the "local handle" also print that variable to the log file, or use dumptable or other commands if it is not a string. Just to see exactly what you are getting back.
Pay special attention to the / and \. In Dzvents the \ is a special character to make sure he next character is not interpreted as special but just taken as-is. for example the ".
Who is online
Users browsing this forum: No registered users and 1 guest