I’m totally missing something here or making a stupid error but I cannot find out where or why, does anyone know why this code fails?
[tt]local time_tmp = 0
local time_post_tmp = 0
local time_get_tmp = 0
local gasvaluetemp = 0
local average_temp_outside = 0
local degreedays = 0
local divtest = 0
local divtest1 = 1
local divtest2 = 1
local status_get, result_get = luup.inet.wget(“http://emoncmsURL/feed/data.json?id=1&start=” … time_get_tmp … “&end=&dp=}”, 5) --result format [[1385420400000,“3.03”]]
gasvaluetemp = string.match(result_get, ‘%b""’) --gasvaluetemp format 3.03, checks out fine
[quote=“arjenhiemstra, post:1, topic:177982”]average_temp_outside = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“yesterdaysAverage”, 180)
degreedays = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“yesterdaysDegreeDaysHeat”, 180)[/quote]
Dis you set somewhere this two variables : “yesterdaysAverage”, “yesterdaysDegreeDaysHeat”? If not, the result returned by lupp.variable_get is “nil”.
That’s why your code fails. you must set this variables first. Create another scene with some luup code that sets those variable, and after that your code should be ok.
I used this piece of code for both values (with different variables):
[tt]if not tonumber(gasvaluetemp) then
gasvaluetemp = 1
else
gasvaluetemp = tonumber(gasvaluetemp)
end
[/tt]
Turns out this check always returned 1 as result because:
string.match(result_get, ‘%b""’) on the following string: [tt][[1385420400000,“3.03”]][/tt]
Returns [tt]"3.03"[/tt] (so with escape character for the quotes) as a string and this string obviously does not convert to a number…
So, a simple [tt]gasvaluetemp = string.sub(gasvaluetemp, 2, -2)[/tt] solves this issues and now it works!
Thanks!
Best Home Automation shopping experience. Shop at Ezlo!