Page 1 of 1

preceding 0, in values devices

Posted: Monday 06 March 2017 21:32
by curious
I use the "buienradar-plugin" to retrieve values for windspeed etc.
I run a lua script set these values to some dummy devices (type wind)

After running the script the values are :
2017-03-06 20:59:46.933 LUA: Windmeter: Winddirection (in degrees) is: 30
2017-03-06 20:59:46.934 LUA: Windmeter: Winddirection is: NNE
2017-03-06 20:59:46.934 LUA: Windmeter: Windspeed is: 22
2017-03-06 20:59:46.934 LUA: Windmeter: Windgust is: 29
2017-03-06 20:59:46.934 LUA: Windmeter: Windtemperature is: 6.1
2017-03-06 20:59:46.934 LUA: Windmeter: Windfeel is: 4.5

In every weather device the value is preceeded by 0,
So Winddirection in degrees is 0,30
Winddirection is 0,NNE

and so on

How do I get rid of the 0,

This is my code :

Code: Select all

--Windmeter data:

local idxt = 365 --idx of the virtual temperature sensor you need to change this to your own Device IDx
local idxh = 366 --idx of the virtual humidity sensor you need to change this to your own Device IDx
local idxi = 367 --idx of the virtual pressure sensor you need to change this to your own Device IDx
local idxj = 368
local idxk = 369
local idxl = 370




sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues['Buienradar - Wind']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
 
sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

print("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
print("Windmeter: Winddirection is: " .. sWindDirection .. " ");
print("Windmeter: Windspeed is: " .. sWindSpeed .. " ");
print("Windmeter: Windgust is: " .. sWindGust .. " ");
print("Windmeter: Windtemperature is: " .. sWindTemperature .. " ");
print("Windmeter: Windfeel is: " .. sWindFeel .. " ");


commandArray = {}

commandArray[1] = {['UpdateDevice'] = idxt .. '|' .. sWindDirectionDegrees}
commandArray[2] = {['UpdateDevice'] = idxh .. '|' .. sWindDirection}
commandArray[3] = {['UpdateDevice'] = idxi .. '|0|' .. sWindSpeed}
commandArray[4] = {['UpdateDevice'] = idxj .. '|0|' .. sWindGust}
commandArray[5] = {['UpdateDevice'] = idxk .. '|0|' .. sWindTemperature}
commandArray[6] = {['UpdateDevice'] = idxl .. '|0|' .. sWindFeel}

return commandArray 
 

Re: preceding 0, in values devices

Posted: Wednesday 30 August 2017 6:08
by jaras
I run in to the same problem and ended up solving it by using json to update the wind speed value. When I used commandArray I got a 0, (zero comma) prior to the real data.
Here is what I used and so far I just set the windspeed. The actual data is read from file; vind-diff

Code: Select all

pi@NewRpi3 ~/domoticz/scripts/lua $ cat script_time_wind.lua
commandArray = {}
local m = os.date('%M')

if (m % 1 == 0) then
                local sensorId = 33
                WB = 1
                WD = "N"
                TEMP = 85
                WC = 0.1
                local handle = assert (io.open ("/home/pi/rrddata/vind-diff", "r"))
                if (handle) then
                                local w = handle:read("*a")
                                local t = string.gsub(w, "\n", "") -- remove line breaks
                        cmd = "http://192.168.3.181:8090/json.htm?type=command&param=udevice&idx=33&nvalue=0&svalue=%22359;N;" .. tostring(t)  .. ";27.4;8.6;6%22"
                        os.execute("curl '"..cmd.."'")
--                              commandArray[1] = {['UpdateDevice'] = sensorId..'|' .. WB ..'|'.. WD ..'|'..  tostring(t) ..'|'.. TEMP ..'|'.. WC }
                        end
                handle:close()
                end

return commandArray