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 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
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)