WsWin, lua-script to create ws_merge.csv

Moderator: leecollings

Post Reply
Toulon7559
Posts: 858
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

WsWin, lua-script to create ws_merge.csv

Post by Toulon7559 »

The weather software WsWin reads the data from a connected, compatible Personal Weather Station and processes that data for it's database and graphics, and (if desired) for uploads for other applications.

All very nice if your PWS has a balanced & complete set of sensors.
Unfortunately my PWS of type TFA_Nexus has a console-barometer which is 'less-than-excellent' and it misses a sensor for UVI.
The program WsWin has a functionality to look for an additional csv-file with supplementary data:
that supplementary data is then a replacement and/or addition for the data coming (or not) from TFA_Nexus.
Requires the creation of a file ws_merge.csv

The lua-script further down in this message performs that creation based on 'better' data available in Domoticz.
With this script-version the result is a file ws_merge.csv in directory /home/pi for inclusion of Barometric Pressure and UVI.
As indicated at the end of the script, YOU need to organise the required sync/upload to the location of the WsWin main directory.
Also YOU need to adjust the settings in WsWin to activate the link from WsWin to this file ws_merge.csv
Required actions to adjust those settings:
- Switch off 'File/Recording'
- at 'Weatherstation/Filewatching' set a mark for ws_merge.csv
- at 'Weatherstation/Available Sensors' also mark UVI
- if desired, at 'Internet/Sensors' mark UVI
- don't forget to switch on 'File/Recording'!

This lua-script may be applicable for other combinations than WsWin and TFA_Nexus, but generally bear in mind, that with the mechanism of ws_merge.csv you can only overwrite the sensors as listed in WsWin under tab 'Weatherstation/ AvailableSensors'

Code: Select all

-- Script for Domoticz@Raspberry for creation of file ws_merge.csv for upload to WsWin linked to TFA_Nexus (or similar PWS)
-- (C)2018 Toulon7559, version for upload of barometric pressure + UVI for replacement/addition of data  
-- Basic script-version to be tuned for YOUR Configuration of Domoticz
commandArray = {}

-- Line 06, Define input datasources within Domoticz & Settings
Barometer = 'BMP180_Temp_Baro'
UVMeter = 'UVN800'
Interval = 5      -- Interval in minutes
-- Line10, Get Current date & time from os as date.year, date.month, date.day, date.hour, date.min
date = os.date("*t")
year = date.year
month = date.month
if month < 10 then month = "0" .. month
end
day = date.day
if day < 10 then day = "0" .. day
end
hour = date.hour
if hour < 10 then hour = "0" .. hour
end
minutes = date.min
if minutes < 10 then minutes = "0" .. minutes
end

--Line 26, Read-out, Alignment & Compilation for BMP180 barometric pressure
sBMP180T, sBMP180B = otherdevices_svalues[Barometer]:match("([^;]+);([^;]+)")
sBMP180T = tonumber(sBMP180T);
sBMP180B = tonumber(sBMP180B);
a = 1 -- Relative correction for 'true' pressure, a is 0.9 till 1.1 for 10% offset
b = 0 -- Absolute correction for 'true' pressure, b is -10 till + 10 for -/+10 hPa
sBMP180B = (sBMP180B * a) + b
Line01text = string.format("%.2f", (sBMP180B))

-- Line 35, Readout UVI from UVN800
if UVMeter ~= '' then
   UVI0= tonumber(otherdevices_uv[UVMeter])
   Line02text= string.format("%.1f", UVI0)
end

-- Line 41, Make wsmerge_CSV-File for WsWin
-- Extracted (German) text from WsWin_Help-File:  
-- Werden die ID‘s=135(Wind), 136(Windrichtung), 238(Helligkeit), 141(UV), 142(Solarstrahlung), 145(Windböen) verwendet, 
-- dann werden die Merge-Daten nur übernommen, wenn keine Online Daten dafür vorhanden sind
-- Line 45, Define textsegments for wsmerge_CSV-File for WsWin
Line101text = ",,133,141" -- header with identifiers for overwrite in WsWin for relative air pressure and for UVI
Line102text = Line01text -- value for barometric pressure (hPa) linked to ID=133 (for unconditional overwrite)
Line103text = Line02text -- value for UVI (units) linked to ID=141

-- Line 50, Check interval-time and make csv-file
date = os.date("*t")
if (date.min % Interval == 0) then
   file = io.open("/home/pi/ws_merge.csv", "w+")
   -- Opens a file named ws_merge.csv (stored under the designated sub-folder of Domoticz)
   -- File-creation in append mode
   newline="\r\n" -- Line termination by 'return' + 'newline'
   -- write 2 lines to opened file, each line closed by newline
    file:write(Line101text .. newline)
    file:write(day .. "." .. month .. "." .. year .. ",")
    file:write(hour .. ":" .. minutes .. ",")
    file:write(Line102text .. "," .. Line103text .. newline)
    file:close() -- closes the open file
end
-- Line 64, next line is required to set permissions for open&copy&shift&execution of the file 
os.execute("chmod a+rwx /home/pi/ws_merge.csv")
-- Line 66, Lua-Upload-script for ws_merge.csv to follow here
-- Otherwise you have to organise in a different way the sync/upload of ws_merge.csv towards the main directory of WsWin

return commandArray
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest