Lua to virtual multisensor, just short of success? Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
gamlebardun
Posts: 13
Joined: Wednesday 07 November 2018 20:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Location: Jessheim, Norway
Contact:

Lua to virtual multisensor, just short of success?

Post by gamlebardun »

I use http/https polling and a lua script to (eventually) get my virtual multisensor populated with data.

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

gamlebardun
Posts: 13
Joined: Wednesday 07 November 2018 20:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Location: Jessheim, Norway
Contact:

Re: Lua to virtual multisensor, just short of success?

Post by gamlebardun »

it seems this will work:

domoticz_updateDevice(sensorIndex,'',temp .. ";" .. humidity .. ";" .. forecast .. ";" .. barometer .. ";" .. forecast)

now just to figure out what those forecast-values should look like !
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest