Sharing : Afval kalendar in text sensor

Moderator: leecollings

Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Derik »

Dear Jos,

I do have the script in the inter editor... [ better for backups etc etc ]
This works with the "older" script good.
Only i did make a change with the config part
I changed to the last beta..
Now i do have a error..
ScreenShot204.jpg
ScreenShot204.jpg (47.34 KiB) Viewed 2000 times
Can you tell me what here is going wrong..
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

Please show me the whole beginning of the script so I can check if the config part looks ok.
You can also pm it when you prefer.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Derik »

jvdz wrote: Sunday 20 January 2019 21:07 Please show me the whole beginning of the script so I can check if the config part looks ok.
You can also pm it when you prefer.

Jos

Code: Select all

-- afvalWijzer module
--
-- curl in os required!!
-- create dummy text device from dummy hardware with the name defined for: myAfvalDevice
-- Check the timing when to get a notification for each Afvaltype in the afvaltype_cfg table
-- based on script by zicht @ http://www.domoticz.com/forum/viewtopic.php?t=17963
-- based on script by nf999 @ http://www.domoticz.com/forum/viewtopic.php?f=61&t=17963&p=174908#p169637
-----------------------------------------------------------------
-- file: alvalwijzer_userconfig.lua
-- You can define your information in this file without updating the main script eachtime
------------------------------------------------------------------------------------------
myAfvalDevice='D.M.: Afval'                                     -- The Text devicename in Domoticz
ShowNextEvents = 2                                              -- indicate the next x events to show in the TEXT Sensor in Domoticz
Postcode='6344AW'                                               -- Your postalcode
Huisnummer='29'                                                 -- Your housnr
NotificationEmailAdress = "[email protected]"         -- Specify your Email Address for the notifications. Leave empty to skip email notification
Notificationsystem = ""                                         -- Specify notification system eg "telegram/pushover/.." leave empty to skip

-- uncoment any of the below when you need to override the standard settings
--~ -- Switch on Debugging in case of issues => set to true/false=======
--~ debug = false  -- get debug info in domoticz console/log

--~ -- ### define a line for each afvaltype_cfg retuned by the webrequest:
--~ 	-- hour & min ==> the time the check needs to be performed and notification send when daysbefore is true
--~ 	-- daysbefore ==> 0 means that the notification is send on the day of the planned garbage collection
--~	 daysbefore ==> X means that the notification is send X day(s) before the day of the planned garbage collection
--~ 	-- reminder   ==> Will send a second reminder after x hours. 0=no reminder (needs to be in the same day!)
--~ 	-- text       ==> define the text for the notification.

 afvaltype_cfg = {
 	["restafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="Grijze Container met Restafval"},
	["gft"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Groene Container met Tuinfval"},
 	["pmd"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Oranje Container met Plastic en Metalen"},
 	["kerstbomen"]    ={hour=19,min=01,daysbefore=1,reminder=0,text="Kerstbomen"},
 	["takken"]        ={hour=19,min=01,daysbefore=1,reminder=0,text="snoeiafval"},
 	["papier"]        ={hour=12,min=05,daysbefore=0,reminder=0,text="Blauwe Container met Oud papier"},
 	["plastic"]       ={hour=19,min=01,daysbefore=1,reminder=0,text="plastic en drankenkartons"},
 	["grofvuil"]      ={hour=19,min=01,daysbefore=1,reminder=0,text="grofvuil/oud ijzer"},
	["tuinafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="tuinafval"},
--~ -- Add any missing records above this line
--~ 	["dummy1"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update for testing"},
--~ 	["dummy2"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update of text sensor at night"}}

--~ -- Define the Notification Title and body text. there are 3 variables you can include:
--~ -- @DAG@ = Will be replaced by (vandaag/morgen/over x dagen)
--~ -- @AFVALTYPE@ = Will be replaced by the AfvalType found on the internet
--~ -- @AFVALTEXT@ = Will be replaced by the content of the text field for the specific AfvalType in afvaltype_cfg
--~ -- @AFVALDATE@ = Will be replaced by the pickup date found on the internet
 notificationtitle = '@AFW: @DAG@ de @AFVALTEXT@ aan de weg zetten!'
 notificationtext = '@DAG@ wordt de @AFVALTEXT@ opgehaald!'   
  --==== end of config ======================================================================================================
-- General conversion tables
local MON_e_n={January="januari", February="februari", March="maart", April="april", May="mei", June="juni", July="juli", August="augustus", September="september", October="oktober", November="november", December="december"}
local WDAY_e_n={Sunday="zondag", Monday="maandag", Tuesday="dinsdag", Wednesday="woensdag", Thursday="donderdag", Friday="vrijdag", Saturday="zaterdag"}
local MON={januari=1,februari=2,maart=3,april=4,mei=5,juni=6,juli=7,augustus=8,september=9,oktober=10,november=11,december=12}

-- round
break break 
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

You have commented out the 2 dummy lines for the table and the last line is essential to close the Table syntax with the last }. Just leave them in there as they do serve a purpose!

Code: Select all

 afvaltype_cfg = {
 	["restafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="Grijze Container met Restafval"},
	["gft"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Groene Container met Tuinfval"},
 	["pmd"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Oranje Container met Plastic en Metalen"},
 	["kerstbomen"]    ={hour=19,min=01,daysbefore=1,reminder=0,text="Kerstbomen"},
 	["takken"]        ={hour=19,min=01,daysbefore=1,reminder=0,text="snoeiafval"},
 	["papier"]        ={hour=12,min=05,daysbefore=0,reminder=0,text="Blauwe Container met Oud papier"},
 	["plastic"]       ={hour=19,min=01,daysbefore=1,reminder=0,text="plastic en drankenkartons"},
 	["grofvuil"]      ={hour=19,min=01,daysbefore=1,reminder=0,text="grofvuil/oud ijzer"},
	["tuinafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="tuinafval"},
-- Add any missing records above this line
	["dummy1"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update for testing"},
	["dummy2"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update of text sensor at night"}}

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Derik »

Derik wrote: Sunday 20 January 2019 21:25
jvdz wrote: Sunday 20 January 2019 21:07 Please show me the whole beginning of the script so I can check if the config part looks ok.
You can also pm it when you prefer.

Jos

Code: Select all

-- afvalWijzer module
--
-- curl in os required!!
-- create dummy text device from dummy hardware with the name defined for: myAfvalDevice
-- Check the timing when to get a notification for each Afvaltype in the afvaltype_cfg table
-- based on script by zicht @ http://www.domoticz.com/forum/viewtopic.php?t=17963
-- based on script by nf999 @ http://www.domoticz.com/forum/viewtopic.php?f=61&t=17963&p=174908#p169637
-----------------------------------------------------------------
-- file: alvalwijzer_userconfig.lua
-- You can define your information in this file without updating the main script eachtime
------------------------------------------------------------------------------------------
myAfvalDevice='D.M.: Afval'                                     -- The Text devicename in Domoticz
ShowNextEvents = 2                                              -- indicate the next x events to show in the TEXT Sensor in Domoticz
Postcode='6344AW'                                               -- Your postalcode
Huisnummer='29'                                                 -- Your housnr
NotificationEmailAdress = "[email protected]"         -- Specify your Email Address for the notifications. Leave empty to skip email notification
Notificationsystem = ""                                         -- Specify notification system eg "telegram/pushover/.." leave empty to skip

-- uncoment any of the below when you need to override the standard settings
--~ -- Switch on Debugging in case of issues => set to true/false=======
--~ debug = false  -- get debug info in domoticz console/log

--~ -- ### define a line for each afvaltype_cfg retuned by the webrequest:
--~ 	-- hour & min ==> the time the check needs to be performed and notification send when daysbefore is true
--~ 	-- daysbefore ==> 0 means that the notification is send on the day of the planned garbage collection
--~	 daysbefore ==> X means that the notification is send X day(s) before the day of the planned garbage collection
--~ 	-- reminder   ==> Will send a second reminder after x hours. 0=no reminder (needs to be in the same day!)
--~ 	-- text       ==> define the text for the notification.

 afvaltype_cfg = {
 	["restafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="Grijze Container met Restafval"},
	["gft"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Groene Container met Tuinfval"},
 	["pmd"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Oranje Container met Plastic en Metalen"},
 	["kerstbomen"]    ={hour=19,min=01,daysbefore=1,reminder=0,text="Kerstbomen"},
 	["takken"]        ={hour=19,min=01,daysbefore=1,reminder=0,text="snoeiafval"},
 	["papier"]        ={hour=12,min=05,daysbefore=0,reminder=0,text="Blauwe Container met Oud papier"},
 	["plastic"]       ={hour=19,min=01,daysbefore=1,reminder=0,text="plastic en drankenkartons"},
 	["grofvuil"]      ={hour=19,min=01,daysbefore=1,reminder=0,text="grofvuil/oud ijzer"},
	["tuinafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="tuinafval"},
--~ -- Add any missing records above this line
--~ 	["dummy1"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update for testing"},
--~ 	["dummy2"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update of text sensor at night"}}

--~ -- Define the Notification Title and body text. there are 3 variables you can include:
--~ -- @DAG@ = Will be replaced by (vandaag/morgen/over x dagen)
--~ -- @AFVALTYPE@ = Will be replaced by the AfvalType found on the internet
--~ -- @AFVALTEXT@ = Will be replaced by the content of the text field for the specific AfvalType in afvaltype_cfg
--~ -- @AFVALDATE@ = Will be replaced by the pickup date found on the internet
 notificationtitle = '@AFW: @DAG@ de @AFVALTEXT@ aan de weg zetten!'
 notificationtext = '@DAG@ wordt de @AFVALTEXT@ opgehaald!'   
  --==== end of config ======================================================================================================
-- General conversion tables
local MON_e_n={January="januari", February="februari", March="maart", April="april", May="mei", June="juni", July="juli", August="augustus", September="september", October="oktober", November="november", December="december"}
local WDAY_e_n={Sunday="zondag", Monday="maandag", Tuesday="dinsdag", Wednesday="woensdag", Thursday="donderdag", Friday="vrijdag", Saturday="zaterdag"}
local MON={januari=1,februari=2,maart=3,april=4,mei=5,juni=6,juli=7,augustus=8,september=9,oktober=10,november=11,december=12}

-- round
break break 

MM Thanks!!
The red cross in gone..
So i hope this works again..:-)

Can you give me some example of the options is can use for the text sensor and the mail message..
This is higher math for me.

xx
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

Derik wrote: Sunday 20 January 2019 22:09 MM Thanks!!
The red cross in gone..
So i hope this works again..:-)
Nice...
Derik wrote: Sunday 20 January 2019 22:09 Can you give me some example of the options is can use for the text sensor and the mail message..
This is higher math for me.
Not sure what you are asking here... could you explain?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Derik »

Code: Select all

--~ -- Define the Notification Title and body text. there are 3 variables you can include:
--~ -- @DAG@ = Will be replaced by (vandaag/morgen/over x dagen)
--~ -- @AFVALTYPE@ = Will be replaced by the AfvalType found on the internet
--~ -- @AFVALTEXT@ = Will be replaced by the content of the text field for the specific AfvalType in afvaltype_cfg
--~ -- @AFVALDATE@ = Will be replaced by the pickup date found on the internet
 notificationtitle = '@AFW: @DAG@ de @AFVALTEXT@ aan de weg zetten!'
 notificationtext = '@DAG@ wordt de @AFVALTEXT@ opgehaald!'   
This part ..
i can choose only how?


And perhaps a example how to use this:

Code: Select all

--~ -- ### define a line for each afvaltype_cfg retuned by the webrequest:
--~ 	-- hour & min ==> the time the check needs to be performed and notification send when daysbefore is true
--~ 	-- daysbefore ==> 0 means that the notification is send on the day of the planned garbage collection
--~	 daysbefore ==> X means that the notification is send X day(s) before the day of the planned garbage collection
--~ 	-- reminder   ==> Will send a second reminder after x hours. 0=no reminder (needs to be in the same day!)
--~ 	-- text       ==> define the text for the notification.
Or perhaps on git, some examples ?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

Sorry but I am still lost on what you are asking as the quoted parts are an example of the described usage and the table is filled with records using the described options. PM me in Dutch in case you prefer that.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

FYI: @JuanUil ; @freijn ; @rron & Others

I have added script_time_opzet.lua to github with the following commit message:
This script is a generic script for all gemeentes that use the service
of opzet.nl.
This makes the separate scripts for Pumerend, Zuidwest Friesland and
mijnblink (for the gemeentes: Laarbeek, Deurne, Gemert-Bakel,
Heeze-Leende, Someren, Asten en Nuenen) obsolete as they are supported
by this script. check their website for supported gemeentes:
http://www.opzet.nl/afvalkalender_digitaal
or check the afvalkalender of your gemeente and check whether it refers
at the bottom of the page to "Ontwerp & techniek: Opzet".


Also made a change today to fix the abbreviation for Maart from maa to mrt. Might happen again as the months pass by. :)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Derik »

Jos....

I did use the script into the intern lua editor, this was working fine.
Now i changed the head part of the script.. the script is not function any more :-(

Code: Select all

-- afvalWijzer module
--
-- curl in os required!!
-- create dummy text device from dummy hardware with the name defined for: myAfvalDevice
-- Check the timing when to get a notification for each Afvaltype in the afvaltype_cfg table
-- based on script by zicht @ http://www.domoticz.com/forum/viewtopic.php?t=17963
-- based on script by nf999 @ http://www.domoticz.com/forum/viewtopic.php?f=61&t=17963&p=174908#p169637
-----------------------------------------------------------------
-- file: alvalwijzer_userconfig.lua
-- You can define your information in this file without updating the main script eachtime
------------------------------------------------------------------------------------------
myAfvalDevice='D.M.: Afval'                                     -- The Text devicename in Domoticz
ShowNextEvents = 2                                              -- indicate the next x events to show in the TEXT Sensor in Domoticz
Postcode='6678AW'                                               -- Your postalcode
Huisnummer='1'                                                 -- Your housnr
NotificationEmailAdress = "[email protected]"         -- Specify your Email Address for the notifications. Leave empty to skip email notification
Notificationsystem = ""                                         -- Specify notification system eg "telegram/pushover/.." leave empty to skip

-- uncoment any of the below when you need to override the standard settings
--~ -- Switch on Debugging in case of issues => set to true/false=======
--~ debug = false  -- get debug info in domoticz console/log

--~ -- ### define a line for each afvaltype_cfg retuned by the webrequest:
--~ 	-- hour & min ==> the time the check needs to be performed and notification send when daysbefore is true
--~ 	-- daysbefore ==> 0 means that the notification is send on the day of the planned garbage collection
--~	 daysbefore ==> X means that the notification is send X day(s) before the day of the planned garbage collection
--~ 	-- reminder   ==> Will send a second reminder after x hours. 0=no reminder (needs to be in the same day!)
--~ 	-- text       ==> define the text for the notification.

 afvaltype_cfg = {
 	["restafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="Grijze Container met Restafval"},
	["gft"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Groene Container met Tuinfval"},
 	["pmd"]           ={hour=19,min=01,daysbefore=1,reminder=0,text="Oranje Container met Plastic en Metalen"},
 	["kerstbomen"]    ={hour=19,min=01,daysbefore=1,reminder=0,text="Kerstbomen"},
 	["takken"]        ={hour=19,min=01,daysbefore=1,reminder=0,text="snoeiafval"},
 	["papier"]        ={hour=12,min=05,daysbefore=0,reminder=0,text="Blauwe Container met Oud papier"},
 	["plastic"]       ={hour=19,min=01,daysbefore=1,reminder=0,text="plastic en drankenkartons"},
 	["grofvuil"]      ={hour=19,min=01,daysbefore=1,reminder=0,text="grofvuil/oud ijzer"},
	["tuinafval"]     ={hour=19,min=01,daysbefore=1,reminder=0,text="tuinafval"},
--~ -- Add any missing records above this line
--~ 	["dummy1"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update for testing"},
 	["dummy2"]        ={hour=02,min=10,daysbefore=0,reminder=0,text="dummy to trigger update of text sensor at night"}}

--~ -- Define the Notification Title and body text. there are 3 variables you can include:
--~ -- @DAG@ = Will be replaced by (vandaag/morgen/over x dagen)
--~ -- @AFVALTYPE@ = Will be replaced by the AfvalType found on the internet
--~ -- @AFVALTEXT@ = Will be replaced by the content of the text field for the specific AfvalType in afvaltype_cfg
--~ -- @AFVALDATE@ = Will be replaced by the pickup date found on the internet
 notificationtitle = '@AFW: @DAG@ de @AFVALTEXT@ aan de weg zetten!'
 notificationtext = '@DAG@ wordt de @AFVALTEXT@ opgehaald!'   
  --==== end of config ======================================================================================================
-- General conversion tables
local MON_e_n={January="januari", February="februari", March="maart", April="april", May="mei", June="juni", July="juli", August="augustus", September="september", October="oktober", November="november", December="december"}
local WDAY_e_n={Sunday="zondag", Monday="maandag", Tuesday="dinsdag", Wednesday="woensdag", Thursday="donderdag", Friday="vrijdag", Saturday="zaterdag"}
local MON={januari=1,februari=2,maart=3,april=4,mei=5,juni=6,juli=7,augustus=8,september=9,oktober=10,november=11,december=12}

-- round
function Round(num, idp)
   return tonumber(string.format("%." ..(idp or 0).. "f", num))
end
-- debug print
function dprint(text)
   if debug then print("@AFW:"..text) end
end
-- run curl and capture output
function os.capture(cmd, rep)  -- execute command to get site
   -- rep is nr of repeats if result is empty
   local r = rep or 1
   local s = ""
   while ( s == "" and r > 0) do
      r = r-1
      local f = assert(io.popen(cmd, 'r'))
      s = assert(f:read('*a'))
      f:close()
   end
   if ( rep - r > 1 ) then
      print("os.capture needed more than 1 call: " .. rep-r)
   end
  return s
end
-- get days between today and provided date
function getdaysdiff(i_afvaltype_date)
   local curTime = os.time{day=timenow.day,month=timenow.month,year=timenow.year}
   -- Calculate the daysdifference between found date and Now and send notification is required
   local afvalyear =timenow.year
   local afvalday  =timenow.day
   local afvalmonth=timenow.month
   local s_afvalmonth="vandaag"
   -- check if date in variable i_afvaltype_date contains "vandaag" in stead of a valid date -> use today's date
   if string.lower(i_afvaltype_date) == "vandaag" then
      -- use the set todays info
   else
      afvalday,s_afvalmonth=i_afvaltype_date:match("%a+ (%d+) (%a+)")
      if (afvalday == nil or s_afvalmonth == nil) then
         print ('! afvalWijzer: No valid date found in i_afvaltype_date: ' .. i_afvaltype_date)
         return
      end
      afvalmonth = MON[s_afvalmonth]
   end
   dprint("...gerd-> afvalyear:"..tostring(afvalyear).."  s_afvalmonth:"..tostring(s_afvalmonth).."  afvalmonth:"..tostring(afvalmonth).."  afvalday:"..tostring(afvalday))
   --
   local afvalTime = os.time{day=afvalday,month=afvalmonth,year=afvalyear}
   -- return number of days diff
   return Round(os.difftime(afvalTime, curTime)/86400,0)   -- 1 day = 86400 seconds
end

function notification(s_afvaltype,s_afvaltype_date,i_daysdifference)
   --
   dprint("...Noti-> i_daysdifference:"..tostring(i_daysdifference).."  afvaltype_cfg[s_afvaltype].daysbefore:"..tostring(afvaltype_cfg[s_afvaltype].daysbefore).."  hour:"..tostring(afvaltype_cfg[s_afvaltype].hour).."  min:"..tostring(afvaltype_cfg[s_afvaltype].min))
   if afvaltype_cfg[s_afvaltype] ~= nil
   and timenow.hour==afvaltype_cfg[s_afvaltype].hour
   and timenow.min==afvaltype_cfg[s_afvaltype].min
   and i_daysdifference == afvaltype_cfg[s_afvaltype].daysbefore then
      print ('afvalWijzer Notification send for ' .. s_afvaltype)
      dag = ""
      if afvaltype_cfg[s_afvaltype].daysbefore == 0 then
         dag = "vandaag"
      elseif afvaltype_cfg[s_afvaltype].daysbefore == 1 then
         dag = "morgen"
      else
         dag = "over " .. tostring(afvaltype_cfg[s_afvaltype].daysbefore) .. " dagen"
      end
      notificationtitle = notificationtitle:gsub('@DAG@',dag)
      notificationtitle = notificationtitle:gsub('@AFVALTYPE@',s_afvaltype)
      notificationtitle = notificationtitle:gsub('@AFVALTEXT@',tostring(afvaltype_cfg[s_afvaltype].text))
      notificationtitle = notificationtitle:gsub('@AFVALDATE@',s_afvaltype_date)
      notificationtext = notificationtext:gsub('@DAG@',dag)
      notificationtext = notificationtext:gsub('@AFVALTYPE@',s_afvaltype)
      notificationtext = notificationtext:gsub('@AFVALTEXT@',tostring(afvaltype_cfg[s_afvaltype].text))
      notificationtext = notificationtext:gsub('@AFVALDATE@',s_afvaltype_date)
      commandArray['SendEmail'] = notificationtitle .. '#' .. notificationtext .. '#' .. NotificationEmailAdress
   end
end

-- Do the actual update retrieving data from the website and processing it
function Perform_Update()
   print('afvalWijzer module start check')
   dprint('=== web update ================================')
   -- get data from afvalWijzer
   local commando = "curl --max-time 5 -s 'https://www.mijnafvalwijzer.nl/nl/"..Postcode.."/"..Huisnummer.."/'"
   local tmp = os.capture(commando, 5)
   if ( tmp == "" ) then
      print("afvalWijzer: Empty result from curl command")
      return
   end
   -- strip html stuff and format for domoticz
   tmp=tmp:gsub('%c','')
   -- get the data for these fields
   web_afvaldate,web_afvaltype=tmp:match('.-<p class="firstDate">(.-)</p>.-<p class="firstWasteType">(.-)</p>')
   -- replace multiple spaces for only one
   web_afvaltype = string.gsub(web_afvaltype, '%s+', ' ')
   dprint("web_afvaltype:"..tostring(web_afvaltype).."   web_afvaldate:"..tostring (web_afvaldate))
   if (web_afvaldate == nil or web_afvaltype == nil) then
      print ('! afvalWijzer: No valid data found in returned webdata.  skipping the rest of the logic.')
      return
   end
   -- set the date back to a real date to allow for future processing
   if string.lower(web_afvaldate) == "vandaag" then
      if WDAY_e_n[os.date("%A")] == nil then
         dprint(" Error: Not in table WDAY_e_n[]:"..os.date("%A"))
      end
      if MON_e_n[os.date("%B")] == nil then
         dprint(" Error: Not in table MON_e_n[]:"..os.date("%A"))
      end
      web_afvaldate = WDAY_e_n[os.date("%A")].." "..os.date("%d").." "..MON_e_n[os.date("%B")]
      dprint('Change web_afvaldate "vandaag" to :' .. web_afvaldate)
   end
   -- process new information from the web
   daysdifference = getdaysdiff(web_afvaldate)
   if (afvaltype_cfg[web_afvaltype] == nil) then
      print ('! afvalWijzer: Afvalsoort not defined in the "afvaltype_cfg" table for found Afvalsoort : ' .. web_afvaltype)
      return
   end
   notification(web_afvaltype,web_afvaldate,daysdifference)  -- check notification for new found info

   dprint('=== device: ' .. myAfvalDevice .. ' check and update ========')
   -- update device when text changed
   local txt = ""
   curdevtext = otherdevices[myAfvalDevice]
   -- process each record in the device text first to check if still in future and notification needed
   for dev_date, dev_afvaltype in string.gmatch(curdevtext..'\r\n', '(.-)=(.-)\r\n+') do
      dprint("=> process:"..dev_date.."="..dev_afvaltype)
      if web_afvaltype == dev_afvaltype then
         dprint(".> skip same as current domoticz text -> dev_afvaltype:"..dev_date.."="..dev_afvaltype)
      elseif afvaltype_cfg[dev_afvaltype] == nil then
         dprint(".> skip dev_afvaltype as this doesn exist in table:"..dev_afvaltype)
      else
         -- Get DaysDiff
         daysdiffdev = getdaysdiff(dev_date)
         if daysdiffdev == nil  then
            -- something is wrong with the curent text, don't do anything
         elseif daysdiffdev < 0  then
            dprint(".> skip old -> dev_afvaltype:"..dev_date.."="..dev_afvaltype.."   daysdiffdev:"..daysdiffdev)
         else
            dprint(".> Add back to TxtDev -> afvaltype:"..dev_date.."="..dev_afvaltype.."   daysdiffdev:"..daysdiffdev)
            notification(dev_afvaltype,dev_date,daysdiffdev)  -- check notification for new found info
            txt = txt..dev_date .. "=" .. dev_afvaltype .. "\r\n"
         end
      end
   end
   dprint('=== Update TxtDevice in Domoticz =============')
   dprint("=> Add Webinfo to TxtDev -> afvaltype:"..web_afvaltype.." - "..web_afvaldate)
   txt = txt..web_afvaldate .. "=" .. web_afvaltype
   -- always update the domoticz device so one can see it is updating and when it was ran last.
   if (curdevtext ~= txt) then
      commandArray['UpdateDevice'] = otherdevices_idx[myAfvalDevice] .. '|0|' .. txt
      print ('afvalWijzer: Update device from: \n'.. otherdevices[myAfvalDevice] .. '\n replace with:\n' .. txt)
   else
      print ('afvalWijzer: No updated text for TxtDevice.')
   end
end

-- End Functions =========================================================================

-- Start of logic ========================================================================
commandArray = {}
timenow = os.date("*t")

-- check for notification times and run update only when we are at one of these defined times
local needupdate = false
for avtype,get in pairs(afvaltype_cfg) do
   dprint("afvaltype_cfg :"..tostring(avtype)..";"..tostring(afvaltype_cfg[avtype].hour)..";"..tostring(afvaltype_cfg[avtype].min))
   if timenow.hour==afvaltype_cfg[avtype].hour
   and timenow.min==afvaltype_cfg[avtype].min then
      needupdate = true
   end
end
-- get information from website, update device and send notification when required
if needupdate then
   debug = true     -- activate debug here to only log the update process in detail
   Perform_Update()
else
   dprint("Scheduled time(s) not reached yet, so nothing to do!")
end

return commandArray
Hope you can see where there is something wrong..

There is something going on..
Only he says no thing to do?

Code: Select all

 2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :plastic;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :restafval;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :pmd;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :gft;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :dummy2;2;10
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :grofvuil;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :tuinafval;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :papier;12;5
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :takken;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:afvaltype_cfg :kerstbomen;19;1
2019-02-02 20:42:05.787 Status: LUA: @AFW:Scheduled time(s) not reached yet, so nothing to do! 
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

The script will run each minute but It will only do something when one of the times in the table is equal to the actual time.
You have commented the debug=false line so it is showing the extra information like you see in the log.
You should actually not comment that line but change it to debug = true when you want to see the extra debugging information.

All clear? :)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Derik »

yes...
Only the script is not working any more...
The garbage days are not changing?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

Ok, then show me the generate log when a the time it does the update process, so one of the times in the table is the actual time.
You can force this by using one of the dummy lines.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by Derik »

jvdz wrote: Sunday 03 February 2019 9:44 Ok, then show me the generate log when a the time it does the update process, so one of the times in the table is the actual time.
You can force this by using one of the dummy lines.

Jos
Time.. in the table?
The script is running every ,minute...

And the force part i do not understand?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

I know it is running every minute, but as I explained, it doesn't check the data on the website until one of the times in the table is equal to the current time!

Anyways, I looked at the posted code and that looks like an OLD version of the script and not the most recent version on GitHub, which indeed will not run properly in some cases.
Use that latest version from GitHub, update the info at the top and you should be good to go. :)
https://github.com/jvanderzande/mijnafv ... wijzer.lua

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
silver323
Posts: 28
Joined: Friday 01 December 2017 18:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by silver323 »

Installed the script into the intern lua editor but get an error in the log.
It was checking the following from the normal script:
["papier"] ={hour=12,min=05,daysbefore=0,reminder=0,text="Blauwe Container met Oud papier"}

I get the following error:
2019-02-06 12:05:10.389 Error: EventSystem: Warning!, lua script script_time_afvalwijzer has been running for more than 10 seconds
2019-02-06 12:08:27.962 Error: EventSystem: in script_time_afvalwijzer: /home/pi/domoticz/scripts/lua/JSON.lua:1009: /home/pi/domoticz/scripts/lua/JSON.lua:844: Lua script execution exceeds maximum number of lines

What's going wrong?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

No idea. I am not using the internal script editor, but would start with checking the file /home/pi/domoticz/scripts/lua/JSON.lua to see whether it is valid or not in your installation.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
silver323
Posts: 28
Joined: Friday 01 December 2017 18:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by silver323 »

jvdz wrote: Wednesday 06 February 2019 19:32 No idea. I am not using the internal script editor, but would start with checking the file /home/pi/domoticz/scripts/lua/JSON.lua to see whether it is valid or not in your installation.

Jos
It`s in the installation folder json.lua
The role numbers 844 and 1009 are not telling me anything to check.

But i will check if it's gone by putting the script in the lua folder.
Will let you know.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by jvdz »

I have no idea what the limitations are of the build-in implementation, so just try to use it as a time script in a file to see whether that works.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
silver323
Posts: 28
Joined: Friday 01 December 2017 18:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sharing : Afval kalendar in text sensor

Post by silver323 »

jvdz wrote: Wednesday 06 February 2019 20:22 I have no idea what the limitations are of the build-in implementation, so just try to use it as a time script in a file to see whether that works.

Jos
Implemented as time script. But still get the same errors.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest