Page 1 of 1
dzVents - and enabling notification subsystem
Posted: Friday 02 September 2022 18:03
by pipiche
I'm wonder if there is a way to enable/disable a notification subsystem.
For instance I have configured the PushOver Notification subsystem and it is correctly working. My wish is to be able to disable or enable it via a dzVent. Is that something possible ?
I have seem many things to send notifications, but here I just want to enable ALL PushOver notifications or disable them.
Re: dzVents - and enabling notification subsystem
Posted: Monday 05 September 2022 19:53
by hestia
As there is no answer yet, perhaps noting direct so...
Code: Select all
local TEST = 214 -- a dummy device to test the script
local LOG_DEBUG = 1 -- 0 =>ERROR / 1 => FORCE / 2 => DEBUG
local LOG_LEVEL
local LOGGING
if LOG_DEBUG == 2 then
LOGGING = domoticz.LOG_DEBUG
LOG_LEVEL = domoticz.LOG_DEBUG
elseif LOG_DEBUG == 1 then
LOGGING = domoticz.LOG_ERROR
LOG_LEVEL = domoticz.LOG_FORCE
else
LOGGING = domoticz.LOG_ERROR
LOG_LEVEL = domoticz.LOG_INFO
end
return {
logging = {
level = LOGGING
},
on = {
devices = {TEST}
},
execute = function(dz, device)
_G.logMarker = dz.moduleLabel -- set logmarker to scriptname
local _u = dz.utils
-----< BEG FUNCTIONS > ----------------------------------------------------------------------------------------
local function logWrite(str, level) -- Support function for shorthand debug log statements
if level == nil then
level = LOG_LEVEL
end
dz.log(tostring(str), level)
end
local function SelectTablePreferences (p_key)
local _,rc = _u.osCommand('which sqlite3')
if rc == 0 then
local f_cmd, f_result, f_nValue, f_sValue
f_cmd = 'sudo sqlite3 -list -noheader domoticz.db "SELECT nValue, sValue FROM Preferences WHERE Key = \'' .. p_key .. '\' ;"'
logWrite(f_cmd)
f_result = _u.osCommand(f_cmd)
if f_result == nil then
logWrite('SelectTablePreferences ' .. p_key .. ' no entry ,!?', dz.LOG_ERROR)
return -2
else
logWrite('SelectTablePreferences ' .. p_key .. ' => ' .. f_result, dz.LOG_DEBUG)
f_nValue = tonumber(_u.stringSplit(f_result,'|')[1])
f_sValue = _u.stringSplit(f_result,'|')[2]
return f_nValue, f_sValue
end
else
logWrite(' sqlite3 not available. Please make sure it is installed (sudo apt install sqlite3) and accessible', dz.LOG_ERROR)
return -1
end
end
local function UpdateTablePreferences (p_key, p_nValue)
local _,rc = _u.osCommand('which sqlite3')
if rc == 0 then
local f_cmd, f_result, f_nValue, f_sValue
f_cmd = 'sudo sqlite3 -list -noheader domoticz.db "UPDATE Preferences SET nValue = ' .. p_nValue .. ' WHERE Key = \'' .. p_key .. '\' ; commit ;"'
logWrite(f_cmd)
f_result = _u.osCommand(f_cmd)
logWrite(f_result)
if f_result == nil then
logWrite('SelectTablePreferences ' .. p_key .. ' no entry ,!?', dz.LOG_ERROR)
return -2
else
logWrite('SelectTablePreferences ' .. p_key .. ' => ' .. f_result, dz.LOG_DEBUG)
return 0
end
else
logWrite(' sqlite3 not available. Please make sure it is installed (sudo apt install sqlite3) and accessible', dz.LOG_ERROR)
return -1
end
end
-----< END FUNCTIONS > ----------------------------------------------------------------------------------------
local w_Preference = 'PushoverEnabled'
local w_nValue, w_sValue
w_nValue, w_sValue = SelectTablePreferences (w_Preference)
logWrite(w_Preference .. ' BEFORE: nValue ' .. w_nValue .. ' sValue ' .. w_sValue, dz.LOG_FORCE)
local w_nValueNew
if w_nValue == 0 then
w_nValueNew = 1
logWrite('disable to enable', dz.LOG_FORCE)
else
w_nValueNew = 0
logWrite('enable to disable', dz.LOG_FORCE)
end
UpdateTablePreferences(w_Preference, w_nValueNew)
w_nValue, w_sValue = SelectTablePreferences (w_Preference)
logWrite(w_Preference .. ' AFTER: nValue ' .. w_nValue .. ' sValue ' .. w_sValue, dz.LOG_FORCE)
end
}
Re: dzVents - and enabling notification subsystem
Posted: Monday 05 September 2022 21:14
by pipiche
Thanks, but I'm under the impression that is not advised to use sqlite3 and update the Db while Domoticz is running .
Re: dzVents - and enabling notification subsystem
Posted: Monday 05 September 2022 22:23
by hestia
I think is not advised at all to do updates in dz directly with sqllite3 to avoid issues when upgrading.
Specifically while running, I don't know, except to rollback if there is a mistake!
I depends also on the amount of updates, if only once in a while, perhaps this is not an issue
Re: dzVents - and enabling notification subsystem
Posted: Tuesday 06 September 2022 0:08
by waltervl
You could try to find the API call from the settings page through web debug F12. And use that Api call with a openURL script.