Sharing : Afval kalendar in text sensor

Moderator: leecollings

Post Reply
zicht
Posts: 251
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Sharing : Afval kalendar in text sensor

Post by zicht »

Hi

I made a script that will put a text dummy sensor with data of the next garbage calendar date (dutch)
It makes use of the site http://www.mijnafvalwijzer.nl/ so you can test upfront if it works
So you have to make a dummie text sensor in hardware :)

Code: Select all

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  if (dbug == true) then print("Os.Capture") end
  local f = assert(io.popen(cmd, 'r'))
  local s = assert(f:read('*a'))
  f:close()
  if raw then return s end
  s = string.gsub(s, '^%s+', '')
  s = string.gsub(s, '%s+$', '')
  s = string.gsub(s, '[\n\r]+', ' ')
  return s
end

function Afval() 
    -- haal data op van site
	local Postcode='1234AA'
	local Huisnummer='111'
	commando = 'curl -s http://www.mijnafvalwijzer.nl/nl/'..Postcode..'/'..Huisnummer..'/'
	result = os.capture(commando)
 
	-- Beperk string tot infoblock van de site
	local start = string.find(result,'title="Eerstvolgende ophaalmoment"')
	local eind = string.find(result,'class="mobile pageBlock first')
	local nData = string.sub(result, start, eind)
    -- Haal uit het blok de data die nodig is
	local test = " " i=0
	while i<20 and string.find(nData,'>') and string.find(nData,'<',e)  do
		s= string.find(nData,'>') +1  e= string.find(nData,'<',s) -1  l= string.len(nData)
		test = test .. string.sub(nData, s, e)
		nData = string.sub(nData, e, l) 
		i = i+1
	end
	nData = test
	-- strip onnodige troep (die er al het goed is niet is , just to be sure)
	nData = nData:gsub('%W',' ') nData = nData:match("^%s*(.-)%s*$") nData=nData:gsub("%s+", " ")
	return nData
end
I use the function os.capture as i am on windows, do not want to use openurl as i need to capture the content. Its a general function i call more often for other purposed using curl. (standalone curl.exe in domoticz directory)

i call it on time once a day in a lua_time script :

Code: Select all

time = os.date("*t")
if time.hour==7 and time.min<=1 then 
	print('Afval module')
	local IDX = '123'         --your IDX
	local tmp = Afval()
	if otherdevices['Afval Kalender'] ~= tmp then
		commandArray['UpdateDevice'] = IDX..'|0|'..tmp
	end
end
IDX = the idx of you text sensor you need te replace by yours, as wel as you postalcode and housenumber to make things work
Your text sensor will show a message like in my log : 2017-06-15 16:13:02.838 LUA: vandaag Papier en karton maandag 19 juni Restafval
I also push a notification on the text change but you can imagin how that has to be done

If you're free to use or to optimize. ( i am not a coder at al so things are quick an dirty)
Last edited by zicht on Friday 16 June 2017 10:23, edited 3 times in total.
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
pwhooftman
Posts: 75
Joined: Monday 11 November 2013 18:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by pwhooftman »

Nice :)

I grab part of that website to show on my frontpage:

Image
Domoticz v 1.16xx
1X RFXtrx433 USB 433.92MHz Transceiver Firmware version: 71
1X Synology Nas DS918+ DSM 7 (12Gb RAM mod)
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by assenzuid »

Would be great if it's also working with http://www.areareiniging.nl/home/bewone ... -digitaal/
zicht
Posts: 251
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by zicht »

assenzuid wrote:Would be great if it's also working with http://www.areareiniging.nl/home/bewone ... -digitaal/
Just had a look at that site, but its very local (could not find my schedule at all) --> not able to test.
And based on your request i found that not all communties are supported yet on the site i used :shock: (added a link to test in first post)
Can you provide me with some valid input for the site you mentioned ?
(it should be possible to make the script work for all sites as its based on source code reading)
Last edited by zicht on Friday 16 June 2017 10:23, edited 1 time in total.
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by tlpeter »

How easy is it for you to create a script for on a raspberry?
The lua script can be used anyway :D
I went to a raspberry as most script where made for that and now you made one for Windows :mrgreen:
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Thomasdc »

would it be possible to let this work in belgium?
this is a site where the info can be found: http://www.ophaalkalender.be/
zicht
Posts: 251
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by zicht »

tlpeter wrote:How easy is it for you to create a script for on a raspberry?
The lua script can be used anyway :D
I went to a raspberry as most script where made for that and now you made one for Windows :mrgreen:
Thanks, i was surprised to discover the site does not cover all , so added a test link.
It should work from the lua in RPI as well (curl is standard supported normally)
assenzuid wrote:Would be great if it's also working with http://www.areareiniging.nl/home/bewone ... -digitaal/
Thomasdc wrote:would it be possible to let this work in belgium?
this is a site where the info can be found: http://www.ophaalkalender.be/
I read raw source code (as i am not a coder at all i do not know any better way) --> its a matter of having a valid postalcode to see how the site is build and then adjust the search criterea (if you provide me with valid enty i can have a look, its difficult to gues out of the blue :roll: )
But this lua ONLY works if we can get the data visible in the source code of the site !
Last edited by zicht on Friday 16 June 2017 20:33, edited 4 times in total.
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by tlpeter »

I get an error:

017-06-16 11:29:00.336 Error: EventSystem: in AfvalKalender2: [string "..."]:8: attempt to call global 'Afval' (a nil value)

Afval is the function i guess with a tmp but where is that tmp file?
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by tlpeter »

Ok, i just put both scripts in one Lua and now it is working.
I will add some print and notifications in it.

Thanks as i now sometimes forget "oud papier" and "plastic"
zicht
Posts: 251
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by zicht »

tlpeter wrote:Ok, i just put both scripts in one Lua and now it is working.
I will add some print and notifications in it.

Thanks as i now sometimes forget "oud papier" and "plastic"
great that it works out!
No temp file .. why using a temp file if you can use memory ? (thats why i use the os.capture :D )
Indeed the function needs to be availabe for calling in the script :)
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Thomasdc »

zicht wrote:
Thomasdc wrote:would it be possible to let this work in belgium?
this is a site where the info can be found: http://www.ophaalkalender.be/
I read raw source code (as i am not a coder at all i do not know any better way) --> its a matter of having a valid postalcode to see how the site is build and then adjust the search criterea (if you provide me with valid enty i can have a look, its difficult to gues out of the blue :roll: )
postal code: 8554
street name: Kooigemstraat
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Thomasdc »

zicht wrote:
Thomasdc wrote:would it be possible to let this work in belgium?
this is a site where the info can be found: http://www.ophaalkalender.be/
I read raw source code (as i am not a coder at all i do not know any better way) --> its a matter of having a valid postalcode to see how the site is build and then adjust the search criterea (if you provide me with valid enty i can have a look, its difficult to gues out of the blue :roll: )
postal code: 8554
street name: Kooigemstraat
zicht
Posts: 251
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by zicht »

Thomasdc wrote:
Thomasdc wrote:would it be possible to let this work in belgium?
this is a site where the info can be found: http://www.ophaalkalender.be/
Sorry Man : this is beyond my programming skills --> I need to fill in (put) data by a script in the input field (not available via direct link anyway) and i do not know how to do this :( next is that in the source-code the values are not visible after filling in the requested input. As we see it on the display it should be somewhere, but here i also run into skill limitation :(
Would be great if it's also working with http://www.areareiniging.nl/home/bewone ... -digitaal/
Same for this one :( icons in calendar are serverside loaded, no way with my programming skills i can transfer this into something useable for domoticz. Think it could be possible, just lack of skils on my side :( (tested with 7741AM)

Sorry to let you down ...
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
snuiter
Posts: 67
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by snuiter »

Hi tipeter,
can you share the code you have put in Lua, specifically the first script as I am not able to get it working.

Thanks,
Ivo
tlpeter wrote:Ok, i just put both scripts in one Lua and now it is working.
I will add some print and notifications in it.

Thanks as i now sometimes forget "oud papier" and "plastic"
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by tlpeter »

Sure, do not forget to set your postal code and housenumber!!!
Make a virtual text button and give it the name "Afval Kalender"

Code: Select all

commandArray = {}

function os.capture(cmd, raw)            -- os.command uitvoeren en resultaat daarvan lezen in string
  if (dbug == true) then print("Os.Capture") end
  local f = assert(io.popen(cmd, 'r'))
  local s = assert(f:read('*a'))
  f:close()
  if raw then return s end
  s = string.gsub(s, '^%s+', '')
  s = string.gsub(s, '%s+$', '')
  s = string.gsub(s, '[\n\r]+', ' ')
  return s
end

function Afval() 
    -- haal data op van site
   local Postcode='1000AA'
   local Huisnummer='1'
   commando = 'curl -s http://www.mijnafvalwijzer.nl/nl/'..Postcode..'/'..Huisnummer..'/'
   result = os.capture(commando)
 
   -- Beperk string tot infoblock van de site
   local start = string.find(result,'title="Eerstvolgende ophaalmoment"')
   local eind = string.find(result,'class="mobile pageBlock first')
   local nData = string.sub(result, start, eind)
    -- Haal uit het blok de data die nodig is
   local test = " " i=0
   while i<20 and string.find(nData,'>') and string.find(nData,'<',e)  do
      s= string.find(nData,'>') +1  e= string.find(nData,'<',s) -1  l= string.len(nData)
      test = test .. string.sub(nData, s, e)
      nData = string.sub(nData, e, l) 
      i = i+1
   end
   nData = test
   -- strip onnodige troep (die er al het goed is niet is , just to be sure)
   nData = nData:gsub('%W',' ') nData = nData:match("^%s*(.-)%s*$") nData=nData:gsub("%s+", " ")
   return nData
end

time = os.date("*t")
if time.hour==7 and time.min<=1 then 
   print('Afval module')
   local IDX = '2362'         --your IDX
   local tmp = Afval()
   if otherdevices['Afval Kalender'] ~= tmp then
      commandArray['UpdateDevice'] = IDX..'|0|'..tmp
      
     end
end
return commandArray
snuiter
Posts: 67
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by snuiter »

Thanks it is working now
User avatar
K3rryBlue
Posts: 77
Joined: Tuesday 07 February 2017 22:13
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10xx
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by K3rryBlue »

Added a small piece to the code, so Domoticz will sent a notification to my phone, the evening when the garbage needs to be taken outside.

Code: Select all

time = os.date("*t")
-- Only want to be notified on the evenning the garbage can needs to be put outside.
if time.hour==18 and time.min<=1 then 
   print('Afval module')
   local IDX = '400'         --your IDX
   local tmp = Afval()
   if otherdevices['Afval Kalender'] ~= tmp then
      commandArray['UpdateDevice'] = IDX..'|0|'..tmp
   end
   --Added to sent notification, on Tuesday (sunday=1)
   if os.date("*t").wday==3 then
      commandArray['SendNotification']='Garbage can#'..tmp
   end
end
Domoticz V4.10717, RPi2 -> Linux raspberrypi 4.4.47-v7+ , RFXCOM - RFXtrx433 USB 433.92MHz ,RAZBERRY2 and OpenZWave USB Version: 1.4-2363-g1f10253-dirty
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by tlpeter »

K3rryBlue wrote:Added a small piece to the code, so Domoticz will sent a notification to my phone, the evening when the garbage needs to be taken outside.

Code: Select all

time = os.date("*t")
-- Only want to be notified on the evenning the garbage can needs to be put outside.
if time.hour==18 and time.min<=1 then 
   print('Afval module')
   local IDX = '400'         --your IDX
   local tmp = Afval()
   if otherdevices['Afval Kalender'] ~= tmp then
      commandArray['UpdateDevice'] = IDX..'|0|'..tmp
   end
   --Added to sent notification, on Tuesday (sunday=1)
   if os.date("*t").wday==3 then
      commandArray['SendNotification']='Garbage can#'..tmp
   end
end
I am gonna try that one. Tomorrow morning is garbage bin day :-)
It will hopefully send a notification tomorrow morning at 7
User avatar
K3rryBlue
Posts: 77
Joined: Tuesday 07 February 2017 22:13
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10xx
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by K3rryBlue »

tlpeter wrote:
K3rryBlue wrote:Added a small piece to the code, so Domoticz will sent a notification to my phone, the evening when the garbage needs to be taken outside.

Code: Select all

time = os.date("*t")
-- Only want to be notified on the evenning the garbage can needs to be put outside.
if time.hour==18 and time.min<=1 then 
   print('Afval module')
   local IDX = '400'         --your IDX
   local tmp = Afval()
   if otherdevices['Afval Kalender'] ~= tmp then
      commandArray['UpdateDevice'] = IDX..'|0|'..tmp
   end
   --Added to sent notification, on Tuesday (sunday=1)
   if os.date("*t").wday==3 then
      commandArray['SendNotification']='Garbage can#'..tmp
   end
end
I am gonna try that one. Tomorrow morning is garbage bin day :-)
It will hopefully send a notification tomorrow morning at 7

If you change os.date("*t").wday==5 and adjust the time time.hour==7 and time.min<=1 it will ;)
Sunday=1, Monday=2, Tuesday=3, Wednesday=4, Thursday=5, Friday=6 and Saturday=7

If you want a daily update in the text sensor, and once per week an e-mail. You can also use this:

Code: Select all

if time.hour==18 and time.min<=1 then 
   local tmp = Afval()
   if os.date("*t").wday==3 then
      commandArray['SendNotification']='Garbage can#'..tmp
   end
end

if time.hour==7 and time.min<=1 then 
   print('Afval module')
   local IDX = '400'         --your IDX
   local tmp = Afval()
   if otherdevices['Afval Kalender'] ~= tmp then
      commandArray['UpdateDevice'] = IDX..'|0|'..tmp
   end
end
Domoticz V4.10717, RPi2 -> Linux raspberrypi 4.4.47-v7+ , RFXCOM - RFXtrx433 USB 433.92MHz ,RAZBERRY2 and OpenZWave USB Version: 1.4-2363-g1f10253-dirty
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by dutchdevil83 »

For sending a notification one day before the actual pickup day (for example paper day is wednesday but waste day is friday here) i use this code for the notication:

Code: Select all

  --Notification
   if tonumber(os.date("%d")) + 1 ==  tonumber(string.match(tmp, "0*(%d+)")) then
   commandArray['SendNotification']='Afvalwijzer#'..tmp
   end 
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest