Page 1 of 1

Read text file and assign value to virtual temp sensor?

Posted: Monday 19 February 2018 7:39
by landmer
I would like to read a text file located on a local webserver with adress: http://192.168.0.3/rgt.txt
The only contet in the text file is the current exhaust gas tempereature of my boiler with one decimal, example: 231.8

Every five minutes I would like to assign/store the temperature to a virtual temp sensor that I have created with idx: 104

I have found a couple of examples on this forum that is similar and tried to modify them for my needs. But I can't get it to work, so I would be really glad for some help.

Re: Read text file and assign value to virtual temp sensor?

Posted: Monday 19 February 2018 13:52
by elmortero
Maybe post what you have so far here ?

Re: Read text file and assign value to virtual temp sensor?

Posted: Monday 19 February 2018 14:07
by landmer
It was a mess before :lol:
I have tried around with mixing different examples now. And it seems to be working, but I will be glad for any comments to make it more "correct" of course.

Code: Select all

commandArray = {}

now=os.date("*t")
if now.min % 5 == 0 then -- set interval of script running

local f = assert(io.popen("curl -s http://192.168.0.3/rgt.txt" , 'r'))
local rgttemp = assert(f:read('*a'))

print(rgttemp)
commandArray["UpdateDevice"] =  "104|0|".. rgttemp ..""

end

return commandArray

Re: Read text file and assign value to virtual temp sensor?

Posted: Tuesday 15 May 2018 13:58
by jackrobijn
Dear Landsmer

Thry looking in this post regarding setting the lua script correctly

viewtopic.php?t=12087

code for updating the virtual sensor

regards

jack