Send notifications to android app  [Solved]

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

Moderator: leecollings

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Send notifications to android app

Post by snellejellep »

Hi all,

i want to send notifications to the domoticz android app, would like to certain phones only but all of them will also be ok.
i currently have this, i found it on the forum over here.

Code: Select all

dz.notify("ALARM!", "sensor" .. device.name .. "heeft beweging gedetecteerd!", dz.PRIORITY_EMERGENCY,dz.SOUND_DEFAULT, "" , dz.NSS_GOOGLE_CLOUD_MESSAGING)
which does not seem to work.

anyone a suggestion what will work?
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Send notifications to android app

Post by waaren »

snellejellep wrote: Friday 18 October 2019 21:27 i want to send notifications to the domoticz android app, would like to certain phones only but all of them will also be ok.
Syntaxis is OK. Did you set GCM active in the [setup][settings][notification] tab and pressed the test button ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Send notifications to android app

Post by snellejellep »

waaren wrote: Saturday 19 October 2019 1:38 Syntaxis is OK. Did you set GCM active in the [setup][settings][notification] tab and pressed the test button ?
yes, that is turned on and sending a test message that way works too.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Send notifications to android app

Post by waaren »

snellejellep wrote: Saturday 19 October 2019 16:57
waaren wrote: Saturday 19 October 2019 1:38 Syntaxis is OK. Did you set GCM active in the [setup][settings][notification] tab and pressed the test button ?
yes, that is turned on and sending a test message that way works too.
Can you share the complete script and log ? That might help in identifying why the notify does not work as expected.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Send notifications to android app

Post by snellejellep »

sure, this is the script:

Code: Select all

return {
	on = {
		devices = {
			'PIR*',
			'beweging brug',
			'Deur*',
			'roldeur'
		}
	},
	execute = function(dz, device)
		
		local brug          = dz.devices("beweging brug")
		local security      = dz.devices("Domoticz Security Panel").state
		local announce      = dz.variables("Announce")
		
	    if security == "Arm Away" then
	        dz.notify("ALARM!", "sensor" .. device.name .. "heeft beweging gedetecteerd!", dz.PRIORITY_EMERGENCY,dz.SOUND_DEFAULT, "" , dz.NSS_GOOGLE_CLOUD_MESSAGING)
	        announce.set("Er is beweging gedetecteerd door ".. device.name .."")
	    elseif security == "Arm Home" then
	        if brug.lastUpdate.secondsAgo < 5 then
	            dz.notify("ALARM!", "sensor" .. device.name .. "heeft beweging gedetecteerd!", dz.PRIORITY_EMERGENCY,dz.SOUND_DEFAULT, "" , dz.NSS_GOOGLE_CLOUD_MESSAGING)
	        end
	    end
	    
	end
}
and this is my log output:

Code: Select all

2019-10-19 17:43:53.874 Status: dzVents: Info: Handling events for: "PIR schuurzolder", value: "On"
2019-10-19 17:43:53.874 Status: dzVents: Info: ------ Start internal script: Alarm away dzvents: Device: "PIR schuurzolder (Dummy/virtual)", Index: 799
2019-10-19 17:43:53.881 Status: dzVents: Info: ------ Finished Alarm away dzvents
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Send notifications to android app

Post by waaren »

snellejellep wrote: Saturday 19 October 2019 17:46 sure
Can you try this ?

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'PIR*',
            'beweging brug',
            'Deur*',
            'roldeur',
            -- 'myTrigger',
        }
    },

    logging =   
    { 
        level = domoticz.LOG_DEBUG, 
        marker = 'secure notify',
    },

    execute = function(dz, device)
        
        local brug          = dz.devices("beweging brug")
        local announce      = dz.variables("Announce")
        
        dz.log('Security state: ' .. dz.security,dz.LOG_DEBUG)
        dz.log('Device ' .. device.name .. ' lastUpdate was ' .. device.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_DEBUG)
        
        if dz.security == dz.SECURITY_ARMEDAWAY then
            dz.notify("ALARM!", "sensor" .. device.name .. "heeft beweging gedetecteerd!", dz.PRIORITY_EMERGENCY,dz.SOUND_DEFAULT, "" , dz.NSS_GOOGLE_CLOUD_MESSAGING)
            announce.set("Er is beweging gedetecteerd door ".. device.name )
        elseif dz.security == dz.SECURITY_ARMEDHOME then
             if brug.lastUpdate.secondsAgo < 5 then
                dz.notify("ALARM!", "sensor" .. device.name .. "heeft beweging gedetecteerd!", dz.PRIORITY_EMERGENCY,dz.SOUND_DEFAULT, "" , dz.NSS_GOOGLE_CLOUD_MESSAGING)
            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
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Send notifications to android app  [Solved]

Post by snellejellep »

that works, thank you verry much!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest