Sharing : Afval kalendar in text sensor

Moderator: leecollings

roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by roblom »

Can someone help me using this script but then whti the HVC company?

Iknow it has something to do with

Code: Select all

http://inzamelkalender.hvcgroep.nl/push/calendar?callback=jQuery20204883549400154621_1493985891393&postcode=1671jv&huisnummer=22&huisletter=&toevoeging=&adresid=999999999&tijdstip_push=0&_=1493985891404
Which i know from this topic.
http://www.domoticz.com/forum/viewtopic ... 67&t=17432
User avatar
supergroover
Posts: 23
Joined: Friday 12 July 2013 19:37
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by supergroover »

can some one help me with http://www.deafvalapp.nl ?

Code: Select all

http://dataservice.deafvalapp.nl//dataservice/DataServiceServlet?service=OPHAALSCHEMA&land=NL&postcode=6658GT&straatId=0&huisnr=69
Gives me

Code: Select all

GFT;29-12-2017;15-12-2017;01-12-2017;17-11-2017;03-11-2017;20-10-2017;06-10-2017;22-09-2017;08-09-2017;25-08-2017;11-08-2017;28-07-2017;14-07-2017;30-06-2017;16-06-2017;02-06-2017;19-05-2017;05-05-2017;21-04-2017;07-04-2017;24-03-2017;10-03-2017;24-02-2017;10-02-2017;27-01-2017;13-01-2017;01-09-2017;18-08-2017;04-08-2017;21-07-2017;07-07-2017;23-06-2017;09-06-2017;
PAPIER;02-12-2017;04-11-2017;07-10-2017;02-09-2017;05-08-2017;01-07-2017;03-06-2017;06-05-2017;01-04-2017;04-03-2017;04-02-2017;07-01-2017;
PLASTIC;23-12-2017;11-12-2017;27-11-2017;13-11-2017;30-10-2017;16-10-2017;02-10-2017;18-09-2017;04-09-2017;21-08-2017;07-08-2017;24-07-2017;10-07-2017;26-06-2017;12-06-2017;29-05-2017;15-05-2017;01-05-2017;15-04-2017;03-04-2017;20-03-2017;06-03-2017;20-02-2017;06-02-2017;23-01-2017;09-01-2017;
REST;22-12-2017;08-12-2017;24-11-2017;10-11-2017;27-10-2017;13-10-2017;29-09-2017;15-09-2017;01-09-2017;18-08-2017;04-08-2017;21-07-2017;07-07-2017;23-06-2017;09-06-2017;26-05-2017;12-05-2017;28-04-2017;14-04-2017;31-03-2017;17-03-2017;03-03-2017;17-02-2017;03-02-2017;20-01-2017;06-01-2017;
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by roblom »

gordonb3 wrote:
roblom wrote:Can someone help me using this script but then whti the HVC company?

Iknow it has something to do with

Code: Select all

http://inzamelkalender.hvcgroep.nl/push/calendar?callback=jQuery20204883549400154621_1493985891393&postcode=1671jv&huisnummer=22&huisletter=&toevoeging=&adresid=999999999&tijdstip_push=0&_=1493985891404
Which i know from this topic.
viewtopic.php?f=67&t=17432
Quite easy by the looks of it. You can reference the Avalex version for extracting the data. The HVC return is in fact much simpler because it has all the data you need in a single call. For next pickup you would want varname[0]['name'] to get the type and varname[0]['dataTime'][0]['date'] for the when.
That's what I thought also. So I did use the Avalex version and tried without any programs knowledge. But after two days of trying to find the right code I quit. The only thing I got was an empty return. It seems that it is to different for me to replicate it to my own situation where in most cases I get someone dome by self learning. So it was double frustrating because it looked easy.
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by roblom »

That I already discovered. But could not find the right command to fill the "jret" value. I keep getting the nill value. I think it has something to with the date data because it has several dates in it.
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

Looks like afvalwijzer.nl is down, it only has a DEMO option.
Script doesn't work anymore either.

The site of the city where i live has a "afvalkalender" online, but i'm not experienced enough on implementing it in the script.
Is there anyone that is willing to give it a go?

The URL is http://afvalkalender.alphenaandenrijn.nl/
and a working postalcode and housenumber is 2403SN/122
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

Goldwing1973 wrote: Thursday 21 September 2017 9:13 Looks like afvalwijzer.nl is down, it only has a DEMO option.
Script doesn't work anymore either.

The site of the city where i live has a "afvalkalender" online, but i'm not experienced enough on implementing it in the script.
Is there anyone that is willing to give it a go?

The URL is http://afvalkalender.alphenaandenrijn.nl/
and a working postalcode and housenumber is 2403SN/122
just tested --> works over here :
Groente-, fruit- en tuinafval 25 sept
Plastic, Metaal en Drinkpakken 2 okt
Papier en karton 11 okt
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)
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

zicht wrote: Thursday 21 September 2017 21:15
Goldwing1973 wrote: Thursday 21 September 2017 9:13 Looks like afvalwijzer.nl is down, it only has a DEMO option.
Script doesn't work anymore either.

The site of the city where i live has a "afvalkalender" online, but i'm not experienced enough on implementing it in the script.
Is there anyone that is willing to give it a go?

The URL is http://afvalkalender.alphenaandenrijn.nl/
and a working postalcode and housenumber is 2403SN/122
just tested --> works over here :
Groente-, fruit- en tuinafval 25 sept
Plastic, Metaal en Drinkpakken 2 okt
Papier en karton 11 okt

Works? how?
Did you change the URL in the script?? to "commando = 'curl -s http://afvalkalender.alphenaandenrijn.n ... Huisnummer..'/'"?
Tried that here, but i keep seeing "Hello World" in the Dummy text switch.
Could it be because i'm using it on Linux and now Windows?
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

Was it working before ?
Do you have curl installed on windows ? (curl.exe in the domoticz directory ?)

The textfield are a bit different on the site, so you have to search on a different string. But the site works fine.
With small adjustment i got the script working also.

try to change

Code: Select all

	result = os.capture(commando) 
to

Code: Select all

	result = os.capture(commando)
		print (result )
	
so you can see the input you read from the site source ?

-----------------------------------------------------------------------------------

you have a couple of unique strings to search for

<a href="/wat/87" title="Papier en karton"><img src="/media/svg/papier_karton.svg" alt="Papier en karton"/>
<i class="date">

<a href="/wat/113" title="Plastic, Metaal en Drinkpakken"><img src="/media/svg/plastic_blik_drank_logo.svg" alt="Plastic, Metaal en Drinkpakken"/>
<i class="date">

<a href="/wat/112" title="Groente-, fruit- en tuinafval"><img src="/media/svg/gft_appel.svg" alt="Groente-, fruit- en tuinafval"/>
<i class="date">

so you can absolute get the values.
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)
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

zicht wrote: Thursday 21 September 2017 22:04 Was it working before ?
Do you have curl installed on windows ? (curl.exe in the domoticz directory ?)

The textfield are a bit different on the site, so you have to search on a different string. But the site works fine.
With small adjustment i got the script working also.

try to change

Code: Select all

	result = os.capture(commando) 
to

Code: Select all

	result = os.capture(commando)
		print (result )
	
so you can see the input you read from the site source ?

-----------------------------------------------------------------------------------

you have a couple of unique strings to search for

<a href="/wat/87" title="Papier en karton"><img src="/media/svg/papier_karton.svg" alt="Papier en karton"/>
<i class="date">

<a href="/wat/113" title="Plastic, Metaal en Drinkpakken"><img src="/media/svg/plastic_blik_drank_logo.svg" alt="Plastic, Metaal en Drinkpakken"/>
<i class="date">

<a href="/wat/112" title="Groente-, fruit- en tuinafval"><img src="/media/svg/gft_appel.svg" alt="Groente-, fruit- en tuinafval"/>
<i class="date">

so you can absolute get the values.
I'm not using windows, my Domoticz setup is running on a NUC with Ubuntu.
I added the "print (result )" in the script, opened the log... and nothing..
All the regular things show in the logs (OpenZwave, Solar-Data) but no Afvalkalender
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

gordonb3 wrote: Friday 22 September 2017 10:43 Not a very good site, afvalkalender.nl. It mentions something about participating municipalities, but there's no listing of them anywhere. It appears this site is owned by a large waste processing company that operates under various names in different parts of the country and world. That makes it kind of a gamble whether the site will work for you or go to `demo` mode rather than telling you they don't service your area.

As it stands, it looks like Alphen a/d Rijn drew a new contract with a different company.
Agreed about the site only if you local waiste company is under their holding it works,
but for goldwing it should work, (done a test myself.) So something strange is happening over there.

@goldwing i will try to send you a PM with working code for your city, but need to find the time for doing so
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)
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

zicht wrote: Saturday 23 September 2017 19:33
gordonb3 wrote: Friday 22 September 2017 10:43 Not a very good site, afvalkalender.nl. It mentions something about participating municipalities, but there's no listing of them anywhere. It appears this site is owned by a large waste processing company that operates under various names in different parts of the country and world. That makes it kind of a gamble whether the site will work for you or go to `demo` mode rather than telling you they don't service your area.

As it stands, it looks like Alphen a/d Rijn drew a new contract with a different company.
Agreed about the site only if you local waiste company is under their holding it works,
but for goldwing it should work, (done a test myself.) So something strange is happening over there.

@goldwing i will try to send you a PM with working code for your city, but need to find the time for doing so
Thanks, take your time, i’m in no rush
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

Thanks, take your time, i’m in no rush
Basically it is the part where you have to enter your postalcode stops the party.
I need to find out how to get past that landingsite in a smart way.

If they have thought about security it might not be possible at all this way without entering your details manual :shock:
If i juste have visited the site and the cooky or session is placed with you details the script works fine.
But after it expires we have a problem :roll:

note : for privacy reasons i stripped the details from goldwing in the below links and script.

Edit1 :
the url i got by using another site of your city :
http://afvalkalender.alphenaandenrijn.n ... ERIC_CODE>

i just refest and deleted history and that links seems to be correct !
That could be the clue we needed.

Edit2:

Code: Select all

	commando='curl -s http://afvalkalender.alphenaandenrijn.nl/login/<UNIQUENUMERIC_CODE>'
	result=os.capture(commando)
	if string.find(result,"rror") then 
		result="" 
		WriteToFile("Error >>> function 640"..commando,"url")
	end
	print(string.len(result))

	
	-- Beperk string tot infoblock van de site
	local start=string.find(result,'<ul id="ophaaldata">')
	print("start"..tostring(start))
	local eind=string.find(result,'<i>Papier en karton</i></a>',start)
	print("eind"..tostring(eind))
	local nData=string.sub(result, start, eind)
	print(nData)
nData contains the date for 3 different types of waiste.
It is unkown for me how you want to implement... you can split them in any way you want and update 3 diff text devices or make a nice string in one text device.

the print(nDate) above prints the plain HTML code, so it looks a bit odd this way, I put it there to have something to show/debug
Are you able to work with this to make it working in your system ?

Note for others of the same city :
There is a second government site for waiste for you where you can fill in you postal code
If you do it on that site it will redirect you to the site goldwing was using but this time with a unique numeric code in the url for you postal code,
so it lands directly on the waiste page :evil:
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)
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

zicht wrote: Saturday 23 September 2017 20:27
Thanks, take your time, i’m in no rush
Basically it is the part where you have to enter your postalcode stops the party.
I need to find out how to get past that landingsite in a smart way.

If they have thought about security it might not be possible at all this way without entering your details manual :shock:
If i juste have visited the site and the cooky or session is placed with you details the script works fine.
But after it expires we have a problem :roll:

note : for privacy reasons i stripped the details from goldwing in the below links and script.

Edit1 :
the url i got by using another site of your city :
http://afvalkalender.alphenaandenrijn.n ... ERIC_CODE>

i just refest and deleted history and that links seems to be correct !
That could be the clue we needed.

Edit2:

Code: Select all

	commando='curl -s http://afvalkalender.alphenaandenrijn.nl/login/<UNIQUENUMERIC_CODE>'
	result=os.capture(commando)
	if string.find(result,"rror") then 
		result="" 
		WriteToFile("Error >>> function 640"..commando,"url")
	end
	print(string.len(result))

	
	-- Beperk string tot infoblock van de site
	local start=string.find(result,'<ul id="ophaaldata">')
	print("start"..tostring(start))
	local eind=string.find(result,'<i>Papier en karton</i></a>',start)
	print("eind"..tostring(eind))
	local nData=string.sub(result, start, eind)
	print(nData)
nData contains the date for 3 different types of waiste.
It is unkown for me how you want to implement... you can split them in any way you want and update 3 diff text devices or make a nice string in one text device.

the print(nDate) above prints the plain HTML code, so it looks a bit odd this way, I put it there to have something to show/debug
Are you able to work with this to make it working in your system ?

Note for others of the same city :
There is a second government site for waiste for you where you can fill in you postal code
If you do it on that site it will redirect you to the site goldwing was using but this time with a unique numeric code in the url for you postal code,
so it lands directly on the waiste page :evil:
I found the other site, and guess what, If you decrease the unique ID by one, it shows the calendar of my neighbor. (House number on the page decreases).
So we have a working URL that’s independent of a cookie or session ID.

If possible I would like the virtual switch to show what kind of garbage is next in line to be picked up and when.
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

Code: Select all

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  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]+', ' ')
  
	
    end
  return s
end

Code: Select all

	
	commando='curl -s http://afvalkalender.alphenaandenrijn.nl/login/<youruniquecode>'
	result=os.capture(commando)
	if string.find(result,"rror") then 
		result="" 
		WriteToFile("Error >>> function 640"..commando,"url")
	end
	-- Beperk string tot infoblock van de site
	local start=string.find(result,'<ul id="ophaaldata">')
	local eind=string.find(result,'<i>Papier en karton</i></a>',start)
	local nData=string.sub(result, start, eind)
	nData=nData:gsub('%W',' ') nData=nData:match("^%s*(.-)%s*$") nData=nData:gsub("%s+", " ")
	w,x=string.find(nData,"Groente fruit en tuinafval i class date")
	y,z=string.find(nData," i i ",x)
	Groente=string.sub(nData,x+1,y)
	print("Groente,fruit & tuin"..Groente)
	w,x=string.find(nData,"Metaal en Drinkpakken i class date")
	y,z=string.find(nData," i i ",x)
	Metaal=string.sub(nData,x+1,y)
	print("Metaal & Drinkpakken "..Metaal)
	w,x=string.find(nData,"Papier en karton i class date")
	y,z=string.find(nData," i",x)
	Papier=string.sub(nData,x+1,y)
	print("Papier & karton "..Papier)
	
The above create 3 strings and prints them for the 3 types of waiste collection.
The function needs to be available and can be in the same time script as your waiste script.

You only have to put the strings in a text device any way you would like. All are small text so it would fit normally.
So you can add Something like at the end :

Code: Select all

commandArray[#commandArray + 1]={['UpdateDevice']='<YOUR_TEXT_IDX'..'|0|'..Groente.." "..Metaal.." "..Papier}
I think it is not nice to purge the page every minute so i would do it once a day as that would fit the task .
Hint : time = os.date("*t") if (time.hour==7 or time.hour==19) and time.min==0 then .... etc

For today i am done and going to hit my pillow ;)

p.s. I am not a coder at all, so if someone can optimize or has a better solution feel free to teach me "how to" :P
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)
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

zicht wrote: Sunday 24 September 2017 0:50

Code: Select all

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  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]+', ' ')
  
	
    end
  return s
end

Code: Select all

	
	commando='curl -s http://afvalkalender.alphenaandenrijn.nl/login/<youruniquecode>'
	result=os.capture(commando)
	if string.find(result,"rror") then 
		result="" 
		WriteToFile("Error >>> function 640"..commando,"url")
	end
	-- Beperk string tot infoblock van de site
	local start=string.find(result,'<ul id="ophaaldata">')
	local eind=string.find(result,'<i>Papier en karton</i></a>',start)
	local nData=string.sub(result, start, eind)
	nData=nData:gsub('%W',' ') nData=nData:match("^%s*(.-)%s*$") nData=nData:gsub("%s+", " ")
	w,x=string.find(nData,"Groente fruit en tuinafval i class date")
	y,z=string.find(nData," i i ",x)
	Groente=string.sub(nData,x+1,y)
	print("Groente,fruit & tuin"..Groente)
	w,x=string.find(nData,"Metaal en Drinkpakken i class date")
	y,z=string.find(nData," i i ",x)
	Metaal=string.sub(nData,x+1,y)
	print("Metaal & Drinkpakken "..Metaal)
	w,x=string.find(nData,"Papier en karton i class date")
	y,z=string.find(nData," i",x)
	Papier=string.sub(nData,x+1,y)
	print("Papier & karton "..Papier)
	
The above create 3 strings and prints them for the 3 types of waiste collection.
The function needs to be available and can be in the same time script as your waiste script.

You only have to put the strings in a text device any way you would like. All are small text so it would fit normally.
So you can add Something like at the end :

Code: Select all

commandArray[#commandArray + 1]={['UpdateDevice']='<YOUR_TEXT_IDX'..'|0|'..Groente.." "..Metaal.." "..Papier}
I think it is not nice to purge the page every minute so i would do it once a day as that would fit the task .
Hint : time = os.date("*t") if (time.hour==7 or time.hour==19) and time.min==0 then .... etc

For today i am done and going to hit my pillow ;)

p.s. I am not a coder at all, so if someone can optimize or has a better solution feel free to teach me "how to" :P

Well, i'm unable to get it working.. :cry:
Error: EventSystem: in Afvalkalender: [string "commandArray = {}..."]:15: expected near 'end'
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

Sorry for the late reply
Hmmzz
Can you post the code exactly as you have implemnten her ?
You can mask for privacy or use PM is you want.
It is working her ( have a running copy present ) so it must be something small.
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)
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

This is what i got

Code: Select all

commandArray = {}

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  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]+', ' ')
  
	
    end
  return s
end


function Afval() 
    -- haal data op van site
	
	commando='curl -s http://afvalkalender.alphenaandenrijn.nl/login/0484200000000000'
	result=os.capture(commando)
	if string.find(result,"rror") then 
		result="" 
		WriteToFile("Error >>> function 640"..commando,"url")
	end
	-- Beperk string tot infoblock van de site
	local start=string.find(result,'<ul id="ophaaldata">')
	local eind=string.find(result,'<i>Papier en karton</i></a>',start)
	local nData=string.sub(result, start, eind)
	nData=nData:gsub('%W',' ') nData=nData:match("^%s*(.-)%s*$") nData=nData:gsub("%s+", " ")
	w,x=string.find(nData,"Groente fruit en tuinafval i class date")
	y,z=string.find(nData," i i ",x)
	Groente=string.sub(nData,x+1,y)
	print("Groente,fruit & tuin"..Groente)
	w,x=string.find(nData,"Metaal en Drinkpakken i class date")
	y,z=string.find(nData," i i ",x)
	Metaal=string.sub(nData,x+1,y)
	print("Metaal & Drinkpakken "..Metaal)
	w,x=string.find(nData,"Papier en karton i class date")
	y,z=string.find(nData," i",x)
	Papier=string.sub(nData,x+1,y)
	print("Papier & karton "..Papier)
	


    -- 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")
-- 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 = '525'         --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
return commandArray
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

Er zit n end te veel in in het begin, daardoor loopt het vast...
Als die er uit is loopt ie prima hier :)

Code: Select all

commandArray = {}

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  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
	commando='curl -s http://afvalkalender.alphenaandenrijn.nl/login/0484200000000000'
	result=os.capture(commando)
	if string.find(result,"rror") then 
		result="" 
		WriteToFile("Error >>> function 640"..commando,"url")
	end
	-- Beperk string tot infoblock van de site
	local start=string.find(result,'<ul id="ophaaldata">')
	local eind=string.find(result,'<i>Papier en karton</i></a>',start)
	local nData=string.sub(result, start, eind)
	nData=nData:gsub('%W',' ') nData=nData:match("^%s*(.-)%s*$") nData=nData:gsub("%s+", " ")
	w,x=string.find(nData,"Groente fruit en tuinafval i class date")
	y,z=string.find(nData," i i ",x)
	Groente=string.sub(nData,x+1,y)
	print("Groente,fruit & tuin"..Groente)
	w,x=string.find(nData,"Metaal en Drinkpakken i class date")
	y,z=string.find(nData," i i ",x)
	Metaal=string.sub(nData,x+1,y)
	print("Metaal & Drinkpakken "..Metaal)
	w,x=string.find(nData,"Papier en karton i class date")
	y,z=string.find(nData," i",x)
	Papier=string.sub(nData,x+1,y)
	print("Papier & karton "..Papier)

    -- 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")
-- 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 = '525'         --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
return commandArray
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)
Goldwing1973
Posts: 69
Joined: Monday 08 August 2016 22:55
Target OS: Linux
Domoticz version: Stable
Location: Netherlands, Alphen aan den Rijn
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Goldwing1973 »

zicht wrote: Saturday 30 September 2017 23:49 Er zit n end te veel in in het begin, daardoor loopt het vast...
Als die er uit is loopt ie prima hier :)

Code: Select all

commandArray = {}

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  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
	commando='curl -s http://afvalkalender.alphenaandenrijn.nl/login/0484200000000000'
	result=os.capture(commando)
	if string.find(result,"rror") then 
		result="" 
		WriteToFile("Error >>> function 640"..commando,"url")
	end
	-- Beperk string tot infoblock van de site
	local start=string.find(result,'<ul id="ophaaldata">')
	local eind=string.find(result,'<i>Papier en karton</i></a>',start)
	local nData=string.sub(result, start, eind)
	nData=nData:gsub('%W',' ') nData=nData:match("^%s*(.-)%s*$") nData=nData:gsub("%s+", " ")
	w,x=string.find(nData,"Groente fruit en tuinafval i class date")
	y,z=string.find(nData," i i ",x)
	Groente=string.sub(nData,x+1,y)
	print("Groente,fruit & tuin"..Groente)
	w,x=string.find(nData,"Metaal en Drinkpakken i class date")
	y,z=string.find(nData," i i ",x)
	Metaal=string.sub(nData,x+1,y)
	print("Metaal & Drinkpakken "..Metaal)
	w,x=string.find(nData,"Papier en karton i class date")
	y,z=string.find(nData," i",x)
	Papier=string.sub(nData,x+1,y)
	print("Papier & karton "..Papier)

    -- 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")
-- 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 = '525'         --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
return commandArray
Thanks, i copy'd/pasted your code and the errors are gone, now i have to wait until tomorrow night for the "Hello World" to be replaced with the garbage being collected next monday.
Over 50 Z-Wave Devices (Fibaro and Neo), 4xLogitech Hub, 2xPhilips Hue Bridge+55 Lights, 1x Nest Thermostat, 2xNetatmo Weather Station, 1xSkybell v1 Doorbell, 3 Kwikset KEVO Doorlocks and Domoticz running on a Intel NUC
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 »

Thanks, i copy'd/pasted your code and the errors are gone, now i have to wait until tomorrow night for the "Hello World" to be replaced with the garbage being collected next monday.
Your welcome.
Your code will runt twice at 18h00 and 18h01 :) Off course if you want to test you can change 18 to the next hour.
Well done !
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)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests