dzVents - and enabling notification subsystem

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

Moderator: leecollings

Post Reply
pipiche
Posts: 2027
Joined: Monday 02 April 2018 20:33
Target OS: Linux
Domoticz version:

dzVents - and enabling notification subsystem

Post 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.
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: dzVents - and enabling notification subsystem

Post 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
}
pipiche
Posts: 2027
Joined: Monday 02 April 2018 20:33
Target OS: Linux
Domoticz version:

Re: dzVents - and enabling notification subsystem

Post by pipiche »

Thanks, but I'm under the impression that is not advised to use sqlite3 and update the Db while Domoticz is running .
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: dzVents - and enabling notification subsystem

Post 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
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: dzVents - and enabling notification subsystem

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest