probably you trying to set something wrong in you text device.... causing your problems
the gathering from data works well as it prints ok, you mixed the 2 scripts what will not work.
See code below, should work without any problem
You can add notifications and text as you want but be aware if you mallform a text sensor (Length to long or include faulty (HTML)code) this can mess up big time. The text code will print all you put into it, so influences the dashboard webpage !
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)
return Papier, Metaal, Groente
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')
Papier,Metaal,Groente=afval() -- roep functie aan en krijg de datums
local IDX = '525' -- text IDX
commandArray[#commandArray + 1]={['UpdateDevice']=IDX..'|0|Groente '..Groente.." Metaal "..Metaal.." papier"..Papier}
end
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)