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.

Moderators: leecollings, remb0

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

React on RSS feed

Post by MatthijsD »

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: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: React on RSS feed

Post by Westcott »

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, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
MatthijsD
Posts: 45
Joined: Sunday 19 March 2017 11:48
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: React on RSS feed

Post by MatthijsD »

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 11:48
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: React on RSS feed

Post by MatthijsD »

Still unanswered and unsolved!
If anyone can help me out, that would be great :)
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero »

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 11:48
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: React on RSS feed

Post by MatthijsD »

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 »

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 18:08
Target OS: -
Domoticz version:
Contact:

Re: React on RSS feed

Post by dverhall »

Welke RSS feed gebruik je voor de meldingen?
Last edited by dverhall on Wednesday 21 February 2018 20:52, edited 1 time in total.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero »

dverhall wrote: Wednesday 21 February 2018 18: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
}
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: React on RSS feed

Post by EdwinK »

elmortero wrote: Wednesday 21 February 2018 20:27
dverhall wrote: Wednesday 21 February 2018 18: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) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero »

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
clut
Posts: 4
Joined: Sunday 17 March 2019 22:46
Target OS: -
Domoticz version:
Contact:

Re: React on RSS feed

Post by clut »

What am I doing wrong?

I tried to run this script but it didn't work. I made the 2 dummy text sensors named "P2000" and "CapCodes" but they were not filled with text.

Below is a part of my logfile:
2019-03-17 23:07:00.231 Status: dzVents: Info: ------ Start external script: Domoticz-P2000.lua:, trigger: every minute
2019-03-17 23:07:00.268 Status: dzVents: Info: ------ Finished Domoticz-P2000.lua
2019-03-17 23:07:00.306 Status: dzVents: Info: WUS: ------ Finished updateWeatherSensors.lua
2019-03-17 23:07:01.600 Status: dzVents: Info: Handling httpResponse-events for: "Pdroid
2019-03-17 23:07:01.601 Status: dzVents: Info: ------ Start external script: Domoticz-P2000.lua: HTTPResponse: "Pdroid"
2019-03-17 23:07:01.639 Status: dzVents: Info: ------ Finished Domoticz-P2000.lua
2019-03-17 23:08:00.232 Status: dzVents: Info: ------ Start external script: Domoticz-P2000.lua:, trigger: every minute
2019-03-17 23:08:00.269 Status: dzVents: Info: ------ Finished Domoticz-P2000.lua

I don't know how to check what I am doning wrong, if I put the text string direct in a Webbrowser it works normally, like a collection of text :-)

Thanks for help!
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero »

Hi,
Maybe post your complete code, you might have added a non working filter since you do not get errors from dzvents.
clut
Posts: 4
Joined: Sunday 17 March 2019 22:46
Target OS: -
Domoticz version:
Contact:

Re: React on RSS feed

Post by clut »

OKe, here is my code:

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 = 'Amsterdam'
		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 file is saved under: ~/domoticz/scripts/dzVents/scripts as "Domoticz-P2000.lua"

Thanks for help!
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero »

In order to check if it gets any data at all:
move line 49, the one that says print(composed) and put it before line 47 (if composed ~= currInfo then) so that the output is written to log without checking if it is different from the already stored text.
Also: change timer = { 'every minute' } to timer = { 'every 3 minutes' },

Let us know what happens in the logs
clut
Posts: 4
Joined: Sunday 17 March 2019 22:46
Target OS: -
Domoticz version:
Contact:

Re: React on RSS feed

Post by clut »

Thanks for your reply, result looks like the same... I did what you suggested

2019-03-20 18:30:00.378 Status: dzVents: Info: ------ Start external script: Domoticz-P2000.lua:, trigger: every 3 minutes
2019-03-20 18:30:00.416 Status: dzVents: Info: ------ Finished Domoticz-P2000.lua
2019-03-20 18:30:00.454 Status: dzVents: Info: WUS: ------ Finished updateWeatherSensors.lua
2019-03-20 18:30:02.620 Status: dzVents: Info: Handling httpResponse-events for: "Pdroid
2019-03-20 18:30:02.621 Status: dzVents: Info: ------ Start external script: Domoticz-P2000.lua: HTTPResponse: "Pdroid"
2019-03-20 18:30:02.672 Status: dzVents: Info: ------ Finished Domoticz-P2000.lua

And if I put the string direct into a webbrowser I do have the result below:
https://www.alarmeringdroid.nl/api/live ... =Amsterdam
clut
Posts: 4
Joined: Sunday 17 March 2019 22:46
Target OS: -
Domoticz version:
Contact:

Re: React on RSS feed

Post by clut »

Is there maybe another method to find out what is going on? I mean, for some reason I do not have an error, but there is nothing dropped in my sensors so what am I doing wrong?
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero »

clut wrote: Monday 25 March 2019 19:28 Is there maybe another method to find out what is going on? I mean, for some reason I do not have an error, but there is nothing dropped in my sensors so what am I doing wrong?
Hi Clut,

Sorry for the late reply. I don't use the script myself so lost track of the topic.
The issue is that alarmeringdroid does not have it's page headers correct (basically says the content is test instead of json).
I have my own way of solving that and my script relies on that.

The adapted code below checks for that and converts the data to correct json result.
Please have a try, if you still need this.

Code: Select all

return {
  on = {
    timer = { 'every 2 minutes' }, --this might be to low..
    httpResponses = { 'Pdroid' } -- matches callback string below
  },

  execute = function(domoticz, triggerItem)
    local sensor = domoticz.devices('P2000') -- You will need to have a text sensor called P2000
    local currInfo = tostring(sensor.text) -- gets the content of above sensor (so we won't update it with same content)

    -- set the next to parameters to filter results
    local capcode = '' -- seems to work only if also regio of plaats is used
    local regio = ''
    --[[ Possible values for regio are
			  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'
    --[[Possible values for dienst are
			1= Politie 2 = Brandweer 3 = Ambulance 4 = KNRM 5 = Lifeliner 7 = Dares  
			--]]
    local plaats = 'Amsterdam'

    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) then
        if response.isJSON then -- check headers if "Content-Type => application/json" (alarmeringdroid does not)
          --  good, the response is in correct json
        else
          print('p2000 values not JSON, converting it now')
          response = domoticz.utils.fromJSON(response.data) -- converts to real JSON
        end

        tl = #response.items
        tc = 1
        repeat
          local dienst = tostring(response.items[tc].dienst)
          local regio = tostring(response.items[tc].regio)
          local info = tostring(response.items[tc].brandinfo)
          if info == nil then info = '-' end
          local melding = tostring(response.items[tc].msg) --items[0].msg
          local regio = tostring(response.items[tc].regio) --items[0].regio
          local info = tostring(response.items[tc].brandinfo) --items[0].brandinfo
          local lat = tostring(response.items[tc].lat)
          local lon = tostring(response.items[tc].lon)
          local grip = tonumber(response.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 -- Voids the next line to limit the result to last event only. If you want all results comment out this line
          tc = tc + 1 -- increase the counter with 1 in order to get the next (or better, previous) message
        until tc > tl
      end
    else
      print('**Pdroid failed to fetch info')
    end

  end
}

Hope it works for you now.
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: React on RSS feed

Post by EdwinK »

-[[Possible values for dienst are
1= Politie 2 = Brandweer 3 = Ambulance 4 = KNRM 5 = Lifeliner 7 = Dares
If I want to get both the fire-department (brandweer) AND police (Politie), can I then use both their numbers line 1,2,3 etc.?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: React on RSS feed

Post by elmortero »

EdwinK wrote: Saturday 27 July 2019 16:14 If I want to get both the fire-department (brandweer) AND police (Politie), can I then use both their numbers line 1,2,3 etc.?
Seems to work, but with semi-colon (;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest