Notification via nextcloud

Moderator: leecollings

Post Reply
m147
Posts: 27
Joined: Saturday 04 August 2018 14:51
Target OS: Linux
Domoticz version:
Contact:

Notification via nextcloud

Post by m147 »

Hello,
Based on this topic viewtopic.php?f=31&t=35252 I have made simple script to use Nextcloud as notification server.
Thx again @waaren ;)

Code: Select all

return
{
    on =
    {
        customEvents = { "notification" },
        
   
    },

    logging = {
        level = domoticz.LOG_DEBUG,
        marker = notification,
    },

    execute = function(dz, item)
        
        local function notify()
            local ADMIN = "adminuser"
            local TOKEN = "secret-token"
            local USER = "targetuser"
            local MESSAGE = item.data
            dz.executeShellCommand(
            {
                command = 'curl -H "OCS-APIREQUEST: true" -X POST   https://'..ADMIN..':'..TOKEN..'@redandblack.cz/ocs/v2.php/apps/admin_notifications/api/v1/notifications/'..USER..'   -d "shortMessage='..MESSAGE..'"' ,
                timeout = 300,
            })
        end

        if item.isTimer or item.isDevice or item.customEvent then
            notify()
        else
            dz.log(item,dz.LOG_DEBUG)
        end
    end
}
You can activate notification for example by MQTT:

Code: Select all

mosquitto_pub -h domoticz -t domoticz/in -m '{"command":"customevent", "event":"notification","data":"message"}'
Or another dzVents script where will be executed:

Code: Select all

domoticz.emitEvent('notification','message"')
I believe there are many users who uses Domoticz and also Nextcloud, so there will be no need to use 3rd party notification services like Pushbullet for them, since you can install Nextcloud app on any device.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notification via nextcloud

Post by waaren »

m147 wrote: Friday 22 January 2021 14:16 I believe there are many users who uses Domoticz and also Nextcloud, so there will be no need to use 3rd party notification services like Pushbullet for them, since you can install Nextcloud app on any device.
I added some checks and log messages to get the result visible

Code: Select all

scriptVar = 'nextcloudPost'
return
{
    on =
    {
         customEvents =
        {
            scriptVar,
        },

        shellCommandResponses =
        {
            scriptVar,
        }
    },

    logging = {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        local function notify()
            local ADMIN = "adminuser"
            local TOKEN = "secret-token"
            local USER = "targetuser"
            local MESSAGE = item.data or ''
            dz.executeShellCommand(
            {
                command = 'curl -H "OCS-APIREQUEST: true" -X POST   https://'..ADMIN..':'..TOKEN..'@redandblack.cz/ocs/v2.php/apps/admin_notifications/api/v1/notifications/'..USER..'   -d "shortMessage='..MESSAGE..'"' ,
                timeout = 300,
                callback = scriptVar,
            })
        end

        if item.isTimer or item.isDevice or item.isCustomEvent then
            notify()
        elseif item.statusCode ~= 0 then
            dz.log('Problem occurred with curl command. Message is ' .. item.errorText ..'. Returncode is ' .. item.statusCode, dz.LOG_ERROR)
            dz.log(item,dz.LOG_DEBUG)
        elseif item.isXML then
            dz.utils.dumpTable(item.xml)
        end

    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest