React on RSS feed

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.
Post Reply
MatthijsD
Posts: 45
Joined: Sunday 19 March 2017 12:48
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

React on RSS feed

Post by MatthijsD » Friday 08 September 2017 14:16

Hello!

Does anyone know if it is possible to use switches through a RSS feed?

Situation: I want to turn on lights as soon as a RSS feed gets a post with a specifiek strain of text.

Why: I'm a firefighter and I want to turn on certain lights as soon as I get a notification on my pager. Because the pager doesn't have a way to send anything, I want Domoticz to look at an RSS feed.

Can someone help me, or maybe even tell me to look in another direction than RSS?

User avatar
Westcott
Posts: 548
Joined: Tuesday 09 December 2014 18:04
Target OS: Raspberry Pi
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: React on RSS feed

Post by Westcott » Friday 08 September 2017 15:40

Python has an RSS feedreader library.
It seems to be possible in LUA as well, which makes integration easier.
How frequently would you want to check the feed?
Zwave - Sigma Z+ stick, Fibaro 2x FGSD002, FGMS001
Horstmann - 2x HRT4, 2x C-stat-11, 4x ASR-ZW, TKB 2x TZ56, 2x TZ68E
Max-EQ Cube, Valve, Neo 2x door
RFXtrx433E, RFlink - 1byone driveway, doorbell, Oregon and BangGood temp
Wifi - YeeLight RGB, 3x ESP8266

MatthijsD
Posts: 45
Joined: Sunday 19 March 2017 12:48
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: React on RSS feed

Post by MatthijsD » Friday 08 September 2017 16:16

Thank you for your reply!

I'm running on Synology and would like to let it check every 5 seconds, only in a given timeframe.

MatthijsD
Posts: 45
Joined: Sunday 19 March 2017 12:48
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: React on RSS feed

Post by MatthijsD » Thursday 14 September 2017 14:00

Still unanswered and unsolved!
If anyone can help me out, that would be great :)

elmortero
Posts: 233
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero » Thursday 14 September 2017 14:46

This LINK should help you get started.
It is simular to reading from a json table which has many examples here on the Domoticz forum.

MatthijsD
Posts: 45
Joined: Sunday 19 March 2017 12:48
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: React on RSS feed

Post by MatthijsD » Wednesday 20 September 2017 21:37

My script skills are sadly, very rusty.
I looked at other options and got the idea to use IFTTT web, to open an JSON url for a switch as soon as there is a new post in the RSS feed.
This, now resulting in automatically turning on the lights as soon as my pager goes off. Awesome :)

Thanks for the tips!

User avatar
NathanBlissett
Posts: 1
Joined: Monday 25 September 2017 10:21
Target OS: Windows
Domoticz version:
Contact:

Re: React on RSS feed

Post by NathanBlissett » Monday 25 September 2017 10:25

elmortero wrote:
Thursday 14 September 2017 14:46
This LINK should help you get started.
It is simular to reading from a json table which has many examples here on the Domoticz forum.
Thanks for sharing it, elmortero!

dverhall
Posts: 1
Joined: Wednesday 21 February 2018 19:08
Target OS: -
Domoticz version:
Contact:

Re: React on RSS feed

Post by dverhall » Wednesday 21 February 2018 19:11

Welke RSS feed gebruik je voor de meldingen?
Last edited by dverhall on Wednesday 21 February 2018 21:52, edited 1 time in total.

elmortero
Posts: 233
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero » Wednesday 21 February 2018 21:27

dverhall wrote:
Wednesday 21 February 2018 19:11
Hello MatthijsD,

Can you please tell me how you fix it? I work also as a fire-fighter in Holland. Please contact me.
Ok, guys, I didn't realize it was for the P2000 stream.
This code might actually do what you need.
In it's current version it writes it's output to a text device and (as test, I do not live in Holland, I fitered on 'brand' in the URL and Amsterdam in the script. It also writes the detected CAP codes to another text sensor but you could for example have it flip a switch or start a scene on certen cap codes(you own personal or department code)

The code should be very straight forward and easy to customize to your needs.
Edit: I should mention this is dzVents (version from version 2.4 upward)

Code: Select all

return {
	on = {
		timer = { 'at every 3 minutes'},
		httpResponses = { 'P2000' } -- matches callback string below
	},
	
	execute = function(domoticz, triggerItem)
local sensor = domoticz.devices('P2000')
local currInfo = tostring(sensor.text)
local Csensor = domoticz.devices('CapCodes')
local CcurrInfo = tostring(Csensor.text)
		if (triggerItem.isTimer) then
			domoticz.openURL({
				url = 'https://p2000.phlux.eu/v1/event?query=Brand&limit=1',
				method = 'GET',
				callback = 'P2000'
			})
			--print('P2000 triggered by timer')
		elseif (triggerItem.isHTTPResponse) then

	local response = triggerItem
		if not response.isJSON then print('data is not jSon') end
		if (response.ok and response.isJSON) then
			--print('P2000 triggered by callback')
			tl = #response.json.events
			tc = 1
			 repeat
				local bericht = tostring(response.json.events[tc].title)
				if bericht ~= currInfo then
				    if string.find((string.lower(bericht)), "amsterdam") then
				       -- print('bericht gevonden: '..bericht)
				sensor.updateText(bericht)
				print('msg : '..bericht)				
					CE = #response.json.events[tc].capcodes
					ec = 1
					repeat
					 local CAPs = tostring(response.json.events[tc].capcodes[CE].capcode)
						 if CAPs ~= CcurrInfo then
						 --print('Capcode = '..CAPs)
						 Csensor.updateText(CAPs)
						 end
					 ec = ec + 1
				 until ec > CE
				 end
				end
				tc = tc + 1
			 until tc > tl

		end
			else
				print('**P2000 failed to fetch info')
			end
		
	end
}

eventeca
Posts: 4
Joined: Tuesday 13 February 2018 14:29
Target OS: -
Domoticz version:
Contact:

Re: React on RSS feed

Post by eventeca » Thursday 22 February 2018 7:17

Thank you so much!!

User avatar
EdwinK
Posts: 1317
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: React on RSS feed

Post by EdwinK » Wednesday 25 July 2018 9:03

elmortero wrote:
Wednesday 21 February 2018 21:27
dverhall wrote:
Wednesday 21 February 2018 19:11
Hello MatthijsD,

Can you please tell me how you fix it? I work also as a fire-fighter in Holland. Please contact me.
Ok, guys, I didn't realize it was for the P2000 stream.
This code might actually do what you need.
In it's current version it writes it's output to a text device and (as test, I do not live in Holland, I fitered on 'brand' in the URL and Amsterdam in the script. It also writes the detected CAP codes to another text sensor but you could for example have it flip a switch or start a scene on certen cap codes(you own personal or department code)

The code should be very straight forward and easy to customize to your needs.
Edit: I should mention this is dzVents (version from version 2.4 upward)
Code removed to save space

When I go to the url mentioned in the script, I end up with a warning page from Chrome, and then a site about package and such.
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

elmortero
Posts: 233
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero » Wednesday 25 July 2018 12:24

Hi EdwinK,
It seems that that site is down.

I did a quick search and following code should also do what you want:

Code: Select all

return {
	on = {
		timer = { 'every minute' },     --this might be to low..
		httpResponses = { 'Pdroid' } -- matches callback string below
	},
	
	execute = function(domoticz, triggerItem)
local sensor = domoticz.devices('P2000')
local currInfo = tostring(sensor.text)
local Csensor = domoticz.devices('CapCodes')
local CcurrInfo = tostring(Csensor.text)
--parameters to be set (or not, if you leave empty the results will not be filtered )
local capcode = '' --seems to work only if also regio of plaats is used
local regio = ''
--[[  1=Amsterdam-Amstelland 6=Brabant Noord 11=Brabant Zuid-Oost 12=Drenthe 27=Flevoland 7=Friesland 8=Gelderland-Midden 13=Gelderland-Zuid 19=Gooi en Vechtstreek 2=Groningen 25=Haaglanden 5=Hollands Midden 17=IJsselland 9=Kennemerland 15=Limburg-Noord 21=Limburg-Zuid 26=Midden- en West Brabant 3=Noord- en Oost Gelderland 24=Noord-Holland Noord 10=Rotterdam-Rijnmond 23=Twente 18=Utrecht 4=Zaanstreek-Waterland 20=Zeeland
 14=Zuid-Holland Zuid
--]]
local dienst = '2'
--[[1= Politie 2 = Brandweer 3 = Ambulance 4 = KNRM 5 = Lifeliner 7 = Dares  
--]]
local plaats = ''
		if (triggerItem.isTimer) then
			domoticz.openURL({
				url = 'https://www.alarmeringdroid.nl/api/livemon?dienst='..dienst..'&regio='..regio..'&capcode='..capcode..'&plaats='..plaats,
				method = 'GET',
				callback = 'Pdroid'
			})
		elseif (triggerItem.isHTTPResponse) then

	local response = triggerItem
		if (response.ok and response.isJSON) then

			tl = #response.json.items
			tc = 1
			 repeat
				local dienst = tostring(response.json.items[tc].dienst)
				local regio = tostring(response.json.items[tc].regio)
				local info = tostring(response.json.items[tc].brandinfo)
    				if info == nil then info = '-' end
        					local melding = tostring(response.json.items[tc].msg) --items[0].msg
        					local regio = tostring(response.json.items[tc].regio) --items[0].regio
        					local info = tostring(response.json.items[tc].brandinfo) --items[0].brandinfo
        					local lat = tostring(response.json.items[tc].lat)
            				local lon = tostring(response.json.items[tc].lon)
        					local grip = tonumber(response.json.items[tc].grip)
        					local composed = tostring(melding..' ** '..info)
        					     if composed ~= currInfo then
        					      sensor.updateText(composed)
        						  print(composed)
        						        if lon ~= nil then
                						local google = ('https://www.google.com/maps/search/?api=1&query='..lat..','..lon)
                						print(google)
                						end
        						 end

        						tc = tl -- this is to limit the result to only one event. That should do if you set your filters correct
									-- if you want more results comment the line
    					--end
					tc = tc + 1
				 until tc > tl
			end
				else
					print('**Pdroid failed to fetch info')
				end
			
		end
	}
The info about filtering is in the script. If you leave the filter empty it will just be ignored in the URL. I recommend to use as much filtering as possible to make the json smaller (and thus load faster) so there is little chance of missing the alerts you want.
If you don't want the link to google maps (in this script only written to the log) remove lines 50 to 53

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests