The lua-script is close to fulfillment, just lacking the actual returning of data to my virtual sensor .. I would really appreciate help with the final push ?
Virtual sensor is "add hardware", http/https poller with my url. Returns data, all good. Then create virtual sensor, Temp + Humidity + Baro, my idx=135 - and script is /scripts/lua_parsers/yr.lua.
Debugging with print, all values look good, no error messages.. but I must be doing something wrong, perhaps in declaring commandArray, how I use commandArray or formatting of the return value ?
if i print my return value it looks like this, and it is what I intended:
2018-11-18 10:01:46.447 CLuaHandler: udevices: 135|0|1.9;93.1;0;1044.3;0
I have cheated by looking at this viewtopic.php?t=11577
Code: Select all
commandArray = {}
local deviceId = '135'
local s = request['content']
-- Barometric pressure
local p = string.find(s, '<pressure id="pr" unit="hPa" value="')
p = p + string.len('<pressure id="pr" unit="hPa" value="')
local t = string.sub(s, p)
p = string.find(t, '"')
local pressure = string.sub(t, 1, p-1)
--print('pressure='..pressure)
-- Temperature
p = string.find(s, '<temperature id="TTT" unit="celsius" value="')
p = p + string.len('<temperature id="TTT" unit="celsius" value="')
t = string.sub(s, p)
p = string.find(t, '"')
local temperature = string.sub(t, 1, p-1)
--print('temperature='..temperature)
-- Humidity
p = string.find(s, '<humidity value="')
p = p + string.len('<humidity value="')
t = string.sub(s, p)
p = string.find(t, '"')
local humidity = string.sub(t, 1, p-1)
--print('humidity='..humidity)
local humidity_status = '0'
local pressure_trend = '0'
t = deviceId .. '|0|' .. temperature .. ';' .. humidity .. ';' .. humidity_status .. ';' .. pressure -- ';' .. pressure_trend
print(t)
commandArray['UpdateDevice'] = t
return commandArray