dzvents Pushover notification without domoticz.notify  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

dzvents Pushover notification without domoticz.notify

Post by Ragdag »

Both my wife and I have a Pushover account and for I created a Pushover Application for Domoticz, also created a Group with the User ID of my wife and me.
When using

Code: Select all

domoticz.notify("Title", "Message.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , domoticz.NSS_PUSHOVER)
we both get a notification.
Now there are certain notifications that not both of us need to get so it would be nice te be able to create a different App in PushOver that only my wife will get and one just for me.
The problem then becomes that I can't configure that in Domoticz.

Is there an alternative way to send PushOver notification from dzvents
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify

Post by waaren »

Ragdag wrote: Sunday 19 April 2020 20:01 Is there an alternative way to send PushOver notification from dzvents
If you have multiple application API tokens and user/group key s you can do it with

Code: Select all

scriptVar = 'myPushover'

return
{
    on =
    {
        devices =
        {
            'pushOverTrigger',
        },
        httpResponses =
        {
            scriptVar,
        },
    },
   
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar
    },

    execute = function(dz, item)
        
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
        else

            local users = 
            {
                ['Jan'] = { ['token'] = 'a5mxxxxxxxxxxx', ['key'] = 'u1wxxxxxxxxxxxxxxxxxxx' },
                ['Piet'] = { ['token'] = 'a5myyyyyyyyyyyyyyy', ['key'] = 'u1wyyyyyyyyyyyyyyyyyy'},
                ['Joris'] = { ['token'] = 'a5mzzzzzzzzzzzzzz', ['key'] = 'u1w5zzzzzzzzzzzzzzzzzz'},
            }
            
           local function pushover(user, message, title, priority, sound)
                dz.openURL({
                    url = 'https://api.pushover.net/1/messages.json',
                    method = 'POST',
                    callback = scriptVar,
                    postData = 
                    {
                        token = user.token,
                        user =  user.key,
                        message = message,
                        title = title or 'Pushover from dzVents',
                        priority = priority or 0,
                        sound = sound or 'echo',
                    },
                })
            end

            pushover(users.Jan, 'pushover unique user')
            pushover(users.Joris, 'en Corneel','Joris', 1, 'echo' )
            pushover(users.Piet, 'message to piet','Only for Piet', 1, 'siren' )
            
        end
    end
    
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify

Post by Ragdag »

waaren wrote: Sunday 19 April 2020 23:53
Ragdag wrote: Sunday 19 April 2020 20:01 Is there an alternative way to send PushOver notification from dzvents
If you have multiple application API tokens and user/group key s you can do it with

Code: Select all

scriptVar = 'myPushover'

return
{
    on =
    {
        devices =
        {
            'pushOverTrigger',
        },
        httpResponses =
        {
            scriptVar,
        },
    },
   
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar
    },

    execute = function(dz, item)
        
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
        else

            local users = 
            {
                ['Jan'] = { ['token'] = 'a5mxxxxxxxxxxx', ['key'] = 'u1wxxxxxxxxxxxxxxxxxxx' },
                ['Piet'] = { ['token'] = 'a5myyyyyyyyyyyyyyy', ['key'] = 'u1wyyyyyyyyyyyyyyyyyy'},
                ['Joris'] = { ['token'] = 'a5mzzzzzzzzzzzzzz', ['key'] = 'u1w5zzzzzzzzzzzzzzzzzz'},
            }
            
local function pushover(user, message, title, priority, sound)
                dz.openURL({
                    url = 'https://api.pushover.net/1/messages.json',
                    method = 'POST',
                    callback = scriptVar,
                    postData = 
                    {
                        token = user.token,
                        user =  user.key,
                        message = message,
                        title = title or 'Pushover from dzVents',
                        priority = priority or 0,
                        sound = sound or 'echo',
                    },
                })
            end

            pushover(users.Jan, 'pushover unique user')
            pushover(users.Joris, 'en Corneel','Joris', 1, 'echo' )
            pushover(users.Piet, 'message to piet','Only for Piet', 1, 'siren' )
            
        end
    end
    
}
As always fast and perfect 😀
Will give this a try, thank you.
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify

Post by Ragdag »

waaren wrote: Sunday 19 April 2020 23:53
Ragdag wrote: Sunday 19 April 2020 20:01 Is there an alternative way to send PushOver notification from dzvents
If you have multiple application API tokens and user/group key s you can do it with

Code: Select all

scriptVar = 'myPushover'

return
{
    on =
    {
        devices =
        {
            'pushOverTrigger',
        },
        httpResponses =
        {
            scriptVar,
        },
    },
   
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar
    },

    execute = function(dz, item)
        
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
        else

            local users = 
            {
                ['Jan'] = { ['token'] = 'a5mxxxxxxxxxxx', ['key'] = 'u1wxxxxxxxxxxxxxxxxxxx' },
                ['Piet'] = { ['token'] = 'a5myyyyyyyyyyyyyyy', ['key'] = 'u1wyyyyyyyyyyyyyyyyyy'},
                ['Joris'] = { ['token'] = 'a5mzzzzzzzzzzzzzz', ['key'] = 'u1w5zzzzzzzzzzzzzzzzzz'},
            }
            
           local function pushover(user, message, title, priority, sound)
                dz.openURL({
                    url = 'https://api.pushover.net/1/messages.json',
                    method = 'POST',
                    callback = scriptVar,
                    postData = 
                    {
                        token = user.token,
                        user =  user.key,
                        message = message,
                        title = title or 'Pushover from dzVents',
                        priority = priority or 0,
                        sound = sound or 'echo',
                    },
                })
            end

            pushover(users.Jan, 'pushover unique user')
            pushover(users.Joris, 'en Corneel','Joris', 1, 'echo' )
            pushover(users.Piet, 'message to piet','Only for Piet', 1, 'siren' )
            
        end
    end
    
}
Would this be something that I put in each dzvents script or would this be a standalone script which I can call from the scripts I need it in.

For instance I have a simple Washing machine done script, how would I integrate it into that?

Code: Select all

return
{
    on =
    {
        timer = {'every 1 minutes'}
    },
    logging = 
    {
        --level = domoticz.LOG_DEBUG,
        marker = "Wasmachine"
    },
    data = 
    {
       WasmachineTimeout = { initial = 1 },
       WasmachineInUse = { initial = 0 },
    },

    execute = function(domoticz)
        local WasmachineUsage = domoticz.devices(275)
        local WasmachineStandbyUsage = 5.5
        if (WasmachineUsage.actualWatt >= WasmachineStandbyUsage) then
            if (domoticz.data.WasmachineInUse == 0) then
                domoticz.data.WasmachineInUse = 1
                domoticz.notify("Wasmachine aan", "De was wordt gestart.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "Nicky" , domoticz.NSS_PUSHOVER)
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.data.WasmachineTimeout = 1
            end
        end
        if (WasmachineUsage.actualWatt <= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) then
            if (domoticz.data.WasmachineTimeout > 0) then
                domoticz.data.WasmachineTimeout = domoticz.data.WasmachineTimeout - 1
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.data.WasmachineInUse = 0
                domoticz.data.WasmachineTimeout = 1
                domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , domoticz.NSS_PUSHOVER)
                domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL, domoticz.SOUND_NONE, "" , domoticz.NSS_KODI)
            end
        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify  [Solved]

Post by waaren »

Ragdag wrote: Tuesday 21 April 2020 14:36 Would this be something that I put in each dzvents script or would this be a standalone script which I can call from the scripts I need it in.
For instance I have a simple Washing machine done script, how would I integrate it into that?
If you only use it in one or two script then I would integrate it into these scripts like attached.
But if you expect to use it in many scripts then I suggest to make it a dzVents Shared helper function

Code: Select all

scriptVar = 'myPushover'

return
{
    on =
    {
        timer = 
        {
            'every 1 minutes',
        },
        httpResponses = 
        {
            scriptVar,
        },
    },

    logging = 
    {
        --level = domoticz.LOG_DEBUG,
        marker = "Wasmachine"
    },
    
    data = 
    {
       WasmachineTimeout = { initial = 1 },
       WasmachineInUse = { initial = 0 },
    },

    execute = function(domoticz, item)
    	dz = domoticz
    	
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
            return
        end
        
        local function pushover(user, title, message, priority, sound)
            dz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = user.token,
                    user =  user.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local users = 
        {
            ['Jan'] = { ['token'] = 'a5mxxxxxxxxxxx', ['key'] = 'u1wxxxxxxxxxxxxxxxxxxx' },
            ['Piet'] = { ['token'] = 'a5myyyyyyyyyyyyyyy', ['key'] = 'u1wyyyyyyyyyyyyyyyyyy'},
            ['Joris'] = { ['token'] = 'a5mzzzzzzzzzzzzzz', ['key'] = 'u1w5zzzzzzzzzzzzzzzzzz'},
        }

        local WasmachineUsage = domoticz.devices(275)
        local WasmachineStandbyUsage = 5.5
        if (WasmachineUsage.actualWatt >= WasmachineStandbyUsage) then
            if (domoticz.data.WasmachineInUse == 0) then
                domoticz.data.WasmachineInUse = 1
                -- domoticz.notify("Wasmachine aan", "De was wordt gestart.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "Nicky" , domoticz.NSS_PUSHOVER)
                pushover(users.Jan,  "Wasmachine aan", "De was wordt gestart.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT )
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.data.WasmachineTimeout = 1
            end
        end
        if (WasmachineUsage.actualWatt <= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) then
            if (domoticz.data.WasmachineTimeout > 0) then
                domoticz.data.WasmachineTimeout = domoticz.data.WasmachineTimeout - 1
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.data.WasmachineInUse = 0
                domoticz.data.WasmachineTimeout = 1
                -- domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , domoticz.NSS_PUSHOVER)
                pushover(users.Piet,  "Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT )
                domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL, domoticz.SOUND_NONE, "" , domoticz.NSS_KODI)
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify

Post by Ragdag »

waaren wrote: Tuesday 21 April 2020 15:19
Ragdag wrote: Tuesday 21 April 2020 14:36 Would this be something that I put in each dzvents script or would this be a standalone script which I can call from the scripts I need it in.
For instance I have a simple Washing machine done script, how would I integrate it into that?
If you only use it in one or two script then I would integrate it into these scripts like attached.
But if you expect to use it in many scripts then I suggest to make it a dzVents Shared helper function

Code: Select all

scriptVar = 'myPushover'

return
{
    on =
    {
        timer = 
        {
            'every 1 minutes',
        },
        httpResponses = 
        {
            scriptVar,
        },
    },

    logging = 
    {
        --level = domoticz.LOG_DEBUG,
        marker = "Wasmachine"
    },
    
    data = 
    {
       WasmachineTimeout = { initial = 1 },
       WasmachineInUse = { initial = 0 },
    },

    execute = function(domoticz, item)
    
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
            return
        end
        
        local function pushover(user, title, message, priority, sound)
            dz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = user.token,
                    user =  user.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local users = 
        {
            ['Jan'] = { ['token'] = 'a5mxxxxxxxxxxx', ['key'] = 'u1wxxxxxxxxxxxxxxxxxxx' },
            ['Piet'] = { ['token'] = 'a5myyyyyyyyyyyyyyy', ['key'] = 'u1wyyyyyyyyyyyyyyyyyy'},
            ['Joris'] = { ['token'] = 'a5mzzzzzzzzzzzzzz', ['key'] = 'u1w5zzzzzzzzzzzzzzzzzz'},
        }

        local WasmachineUsage = domoticz.devices(275)
        local WasmachineStandbyUsage = 5.5
        if (WasmachineUsage.actualWatt >= WasmachineStandbyUsage) then
            if (domoticz.data.WasmachineInUse == 0) then
                domoticz.data.WasmachineInUse = 1
                -- domoticz.notify("Wasmachine aan", "De was wordt gestart.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "Nicky" , domoticz.NSS_PUSHOVER)
                pushover(users.Jan,  "Wasmachine aan", "De was wordt gestart.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT )
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.data.WasmachineTimeout = 1
            end
        end
        if (WasmachineUsage.actualWatt <= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) then
            if (domoticz.data.WasmachineTimeout > 0) then
                domoticz.data.WasmachineTimeout = domoticz.data.WasmachineTimeout - 1
            elseif (domoticz.data.WasmachineTimeout == 0) then
                domoticz.data.WasmachineInUse = 0
                domoticz.data.WasmachineTimeout = 1
                -- domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , domoticz.NSS_PUSHOVER)
                pushover(users.Piet,  "Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT )
                domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL, domoticz.SOUND_NONE, "" , domoticz.NSS_KODI)
            end
        end
    end
}
This works great, just needed to change the dz.openURL and dz.log to domoticz.openURL and domoticz.log otherwise I got an:

Code: Select all

2020-04-21 17:13:01.368 Error: dzVents: Error: (3.0.2) Wasmachine: An error occurred when calling event handler Was_Notification
2020-04-21 17:13:01.368 Error: dzVents: Error: (3.0.2) Wasmachine: ...z/scripts/dzVents/generated_scripts/Was_Notification.lua:32: attempt to index a nil value (global 'dz')
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify

Post by Ragdag »

waaren wrote: Sunday 19 April 2020 23:53
Ragdag wrote: Sunday 19 April 2020 20:01 Is there an alternative way to send PushOver notification from dzvents
If you have multiple application API tokens and user/group key s you can do it with

Code: Select all

scriptVar = 'myPushover'

return
{
    on =
    {
        devices =
        {
            'pushOverTrigger',
        },
        httpResponses =
        {
            scriptVar,
        },
    },
   
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar
    },

    execute = function(dz, item)
        
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
        else

            local users = 
            {
                ['Jan'] = { ['token'] = 'a5mxxxxxxxxxxx', ['key'] = 'u1wxxxxxxxxxxxxxxxxxxx' },
                ['Piet'] = { ['token'] = 'a5myyyyyyyyyyyyyyy', ['key'] = 'u1wyyyyyyyyyyyyyyyyyy'},
                ['Joris'] = { ['token'] = 'a5mzzzzzzzzzzzzzz', ['key'] = 'u1w5zzzzzzzzzzzzzzzzzz'},
            }
            
           local function pushover(user, message, title, priority, sound)
                dz.openURL({
                    url = 'https://api.pushover.net/1/messages.json',
                    method = 'POST',
                    callback = scriptVar,
                    postData = 
                    {
                        token = user.token,
                        user =  user.key,
                        message = message,
                        title = title or 'Pushover from dzVents',
                        priority = priority or 0,
                        sound = sound or 'echo',
                    },
                })
            end

            pushover(users.Jan, 'pushover unique user')
            pushover(users.Joris, 'en Corneel','Joris', 1, 'echo' )
            pushover(users.Piet, 'message to piet','Only for Piet', 1, 'siren' )
            
        end
    end
    
}
It works but I'm trying to figure out how it works and I understand the most of it but there is one thing that is baffling to me, this piece

Code: Select all

                        token = user.token,
                        user =  user.key,
I would expect it to be users to refer back to the array you created.

Code: Select all

                        token = users.token,
                        user =  users.key,
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify

Post by waaren »

Ragdag wrote: Wednesday 22 April 2020 10:20 I would expect it to be users to refer back to the array you created.

Code: Select all

                        token = users.token,
                        user =  users.key,
In the call to the function I do not pass the complete table users but only the sub-table users.Jan via the first parm (user)
So within the function this sub-table is known as user
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Pushover notification without domoticz.notify

Post by Ragdag »

waaren wrote: Wednesday 22 April 2020 10:59
Ragdag wrote: Wednesday 22 April 2020 10:20 I would expect it to be users to refer back to the array you created.

Code: Select all

                        token = users.token,
                        user =  users.key,
In the call to the function I do not pass the complete table users but only the sub-table users.Jan via the first parm (user)
So within the function this sub-table is known as user
Thank you, I think I understand but I also feel my brain bending while trying to figure it out :lol: .
I've started to experiment with the global_data method you referred to but after spending a few hours on it, building small test portions of code to see if it works I think this might be beyond my grasp :oops:
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest