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
Missing decimal place
Moderator: leecollings
-
- Posts: 245
- Joined: Wednesday 17 February 2016 22:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Germany
- Contact:
Re: Missing decimal place
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.
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.
Who is online
Users browsing this forum: No registered users and 1 guest