Page 1 of 1

Missing decimal place

Posted: Saturday 26 August 2017 10:43
by sailmich
Domoticz V3.8337
RPi2
Aeotec Z-Stick Gen5

Hi,
I need help with a Lua script which I found here in the forum and modificated sligthly to my needs. I have a personal weather station which produce a xml file every minute. With the script I grab the windspeed value and update a virtual custom sensor. Problem is the sensor just showing numbers without decimal place. I.e. xml value is 0.7 while virtual sensor showing 0.
Would be fine if somebody could give me the right kick to add a decimal place to my virtual sensor.
I'm more the visuell guy, I prefer Blockly and therefore I would like to use this virtual sensor.
Appreciate any help from you.
Mike

See below the script

-- Title: script_device_weewx.lua
-- Date: 10-01-2016
-- this script reads the weewxpws xml file and uploads current data to virtual device

commandArray = {}
time = os.date("*t")
if ((time.min % 1)==0) then

os.execute('sudo wget http://168.xx.xx.xx/weewx_pws.xml -O /home/pi/domoticz/scripts/lua/weewx_pws.xml')

local filename = "/home/pi/domoticz/scripts/lua/weewx_pws.xml"

local line = ''
local windspeed = 0
local speeddevice = ''

for line in io.lines(filename) do
if string.find(line,"\"windspeed\"") then
windspeed=tonumber(string.match(line, "%d+"))
end
end

-- Update virtual device id
speeddevice='132|0|'..windspeed..';0'

--print(speeddevice))

commandArray['UpdateDevice'] = speeddevice
end
return commandArray

Re: Missing decimal place

Posted: Monday 28 August 2017 21:35
by sailmich
Solve it.
windspeed=tonumber(string.match(line, "%d+")) just deliver value before the decimal point. Instead of "%d+" use "%d+ . %d+" and I get the digit behind the decimal point.