Which means:
- generate a html-file in specific layout
- put that file at location accessible by AWEKAS
- AWEKAS will grab it for further processing
The software setup described in this message performs the job, but as usual 'it is best effort DIY, as-is, for personal use / own risc, to be adapted for YOUR configuration'.
The lua-script below realises the following functions:
- execute the script at the rate set as set for interval (now 15 minutes)
- take the data as inputs from Domoticz as defined [you have to adapt that definitions for your own configuration]
Probably most of you will not have the 2 measurements of Light by ESP8266s. Take out or de-activate/comment the applicable input-definitions if not needed, and accordingly adapt the applicable lines further down in the script
- application of metric units. For that case the script only applies the conversion-function for luxtoWattsm2.
If you want to apply imperial units, then you have to change the unit-definitions, you need all conversion-functions, and you have to exchange the related formatting script lines for those applying the functions incl. call to the conversion-functions
- application of local time instead of UTC
- for barometer and rain facilities to insert an offset relative to the available input data
- conversion the data in the formats required for the html-file
- generation of the html-file by filling each line of the html-file, either by dynamic info prepared by the proceeding formatting script-lines, or by 'fixed' text.
- at the end of the script change the permissions of the html-file to allow transfer & application
- put the html-file in folder /home/pi/
Code: Select all
-- AWEKAS PWS upload script version 1c for Domoticz@Raspberry3 with RFLinkGateway
-- (C)2013 GizMoCuz for WeatherUnderground_Upload, adapted by Toulon7559 for periodic upload to AWEKAS of WS7000-info received via RFLink, extended by SolarRadiation info from calculation, Si1145 and TSL2561
-- This script produces a html-file in accordance with upload-format for AWEKAS Weatherlink HTX-template
commandArray = {}
-- Line 07, Define inputs from Domoticz
Outside_Temp_Hum = 'WS7000A_Temp_RV_Hoog'
Outside_Temp_Soil = 'WS7000B_Temp_RV_Bodem'
Barometer = 'WS7000_Temp_RV_Baro'
RainMeter = 'WS7000_Neerslag'
WindMeter = 'WS7000_Wind'
UVMeter = 'UVN800'
LuxMeter = 'Lux_Calc' -- calculated Lux-value (placeholder/fallback by the script from jmleglise)
SolarRad1 = 'ESP8266C_Licht1' -- measured lux-value1 (experimental)
SolarRad2 = 'ESP8266C_Licht2' -- measured lux-value2 (experimental)
-- Line 18, Define Settings & Units & Offsets
-- If Alternative units are used, then align the readouts by activation of the related dashed lines!
Interval = 15 -- Interval foor execution of script
Line10text ="Unknown" -- 5 Legal texts "Rising Rapidly" "Rising Slowly" "Steady" "Falling Slowly" "Falling Rapidly"
-- For Line10text any other string than the 5 legal texts is illegal and not shown
Line23text ="°C" -- Alternative is "°F"
Line24text ="%"
Line25text ="m/s" -- Alternative is "mph"
Line26text ="hPa" -- Alternative is "in"
Line27text ="mm" -- Alternative is "in"
Line28text ="W/m²"
Line29text ="mm/hr" -- Alternative is "in/hr"
Line30text ="index"
-- Setting of an offset is only meaningful after extended comparison of the sensor information against calibrated information such as from an official meteorological station
a = 1 -- relative correction for rain_day, default is 1, range from 0.9 to 1.1 for max. 10% offset
b = 1 -- relative correction for rain_lasthour, default is 1, range from 0.9 to 1.1 for max. 10% offset
-- absolute correction for rain_day and for rain_lasthour is 0, because otherwise strange bias each day at 00:00
c = 1 -- relative correction for air pressure in hPa, default is 1, range from 0.9 to 1.1 for max. 10% offset
d = 0 -- absolute correction for air pressure in hPa, default is 0, practical range from -10 to +10
-- Line 38, Define Functions
local function CelciusToFarenheit(C)
return (C * (9/5)) + 32
end
local function hPatoInches(hpa)
return hpa * 0.0295301
end
local function mmtoInches(mm)
return mm * 0.039370
end
local function luxtoWattsm2(Lx)
-- if Lx == nil then return 0 end
return Lx * 0.0079
end
-- Line 56= Get Current date & time from os as date.year, date.month, date.day, date.hour, date.min, date.sec
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
hourvalue = hour
if hour < 10 then hour = "0" .. hour
end
minutes = date.min
if minutes < 10 then minutes = "0" .. minutes
end
seconds = date.sec
if seconds < 10 then seconds = "0" .. seconds
end
-- Line 76, Read-out & Compilation of Lux-value
-- Data Extraction1 from svalues for Solarradiation-info
sLux = tonumber(otherdevices_svalues[LuxMeter])
--sLux = 1000 -- Placeholder for testing
LuxLvl = tonumber(sLux);
print ('Lux-level = '.. LuxLvl)
-- Line 82, Experimental readout & processing of measured Lux-values
-- Data Extraction2 from svalues for Solarradiation-info
sLux1 = tonumber(otherdevices_svalues[SolarRad1])
-- sLux1 = 500 -- Placeholder for testing
sLux2 = tonumber(otherdevices_svalues[SolarRad2])
-- sLux2 = 1000 -- Placeholder for testing
LuxDif = sLux1 - sLux2
if sLux1 > sLux2 then
LuxMax = tonumber(sLux1)
else
LuxMax = tonumber(sLux2)
end
print ('Lux1 = '.. sLux1)
print ('Lux2 = '.. sLux2)
print ('Lux_Max = '.. LuxMax)
print ('Lux1-Lux2 = '.. LuxDif)
-- Line 99, Readout Temperature & Humidity
if Outside_Temp_Hum ~= '' then
Line02text= string.format("%3.1f", (otherdevices_temperature[Outside_Temp_Hum]))
-- Line02text= string.format("%3.1f", CelciusToFarenheit(otherdevices_temperature[Outside_Temp_Hum]))
Line03text= string.format("%.0f", (otherdevices_humidity[Outside_Temp_Hum]))
end
-- Line 106, Readout Barometer
if Barometer ~= '' then
Line04text = string.format("%2.2f", ((otherdevices_barometer[Barometer])*c + d))
-- Line04text = string.format("%2.2f", hPatoInches((otherdevices_barometer[Barometer])*c + d))
end
-- Line 112, Readout of Rainvalues
if RainMeter ~= '' then
Line05text= string.format("%2.2f", ((otherdevices_rain[RainMeter])*a + b))
-- Line05text= string.format("%2.2f", mmtoInches((otherdevices_rain[RainMeter])*a + 0)
Line21text= string.format("%2.2f", ((otherdevices_rain_lasthour[RainMeter])*b + 0))
-- Line21text= string.format("%2.2f", mmtoInches((otherdevices_rain_lasthour[RainMeter])*b + 0)
end
-- Line 123, Readout wind direction & speed
if WindMeter ~= '' then
Line06text= string.format("%.0f", (otherdevices_windspeed[WindMeter]))
-- Line06text= string.format("%.0f", (otherdevices_windspeed[WindMeter]/0.1)*0.223693629205)
Line07text= string.format("%.0f", (otherdevices_winddir[WindMeter]))
-- Line07text= string.format("%.0f", (otherdevices_winddir[WindMeter]))
Line18text= string.format("%.0f", (otherdevices_windgust[WindMeter]))
-- Line18text= string.format("%.0f", (otherdevices_windgust[WindMeter]/0.1)*0.223693629205)
end
-- Line 133, Readout Light, calculated
if LuxMeter ~= '' then
Line19text= string.format("%.0f", luxtoWattsm2(LuxLvl))
end
-- Line 137, Readout SolarRad1 = Light, measured
-- if (SolarRad1 ~= '') OR (SolarRad2 ~= '') then
-- Line19text= string.format("%.1f", luxtoWattsm2(LuxMax))
-- end
-- Line 142, Readout UVI
if UVMeter ~= '' then
Line20text= string.format("%.1f", (otherdevices_uv[UVMeter]))
end
-- Line 147, Readout Soil Temperature
if Outside_Temp_Soil ~= '' then
Line22text= string.format("%3.1f", (otherdevices_temperature[Outside_Temp_Soil]))
-- Line22text= string.format("%3.1f", CelciusToFarenheit(otherdevices_temperature[Outside_Temp_Soil]))
end
-- Line 153, Check interval-time and make htm-file
date = os.date("*t")
if (date.min % Interval == 0) then
file = io.open("/home/pi/awekas_wl.html", "w+")
-- Opens a file named awekas_wl.html (stored under the designated sub-folder of Domoticz)
-- in append mode
-- write 31 lines to opened file
file:write("AWEKAS_Template_start<br>\n")
file:write(Line02text .. "<br>\n")
file:write(Line03text .. "<br>\n")
file:write(Line04text .. "<br>\n")
file:write(Line05text .. "<br>\n")
file:write(Line06text .. "<br>\n")
file:write(Line07text .. "<br>\n")
file:write(hour .. ":" .. minutes .. "<br>\n")
file:write(day .. "." .. month .. "." .. year .. "<br>\n")
file:write(Line10text .. "<br>\n")
file:write("-<br>\n")
file:write("-<br>\n")
file:write("-<br>\n")
file:write("-<br>\n")
file:write("-<br>\n")
file:write("-<br>\n")
file:write("-<br>\n")
file:write(Line18text .. "<br>\n")
file:write(Line19text .. "<br>\n")
-- If no Light, then replace above line by file:write("-<br>\n")
file:write(Line20text .. "<br>\n")
-- If no UV, then replace above line by file:write("-<br>\n")
file:write(Line21text .. "<br>\n")
file:write(Line22text .. "<br>\n")
-- If no soiltemp, then replace above line by file:write("-<br>\n")
file:write(Line23text .. "<br>\n")
file:write(Line24text .. "<br>\n")
file:write(Line25text .. "<br>\n")
file:write(Line26text .. "<br>\n")
file:write(Line27text .. "<br>\n")
file:write(Line28text .. "<br>\n")
file:write(Line29text .. "<br>\n")
file:write(Line30text .. "<br>\n")
file:write("Template_V1.5<br>\n")
file:close() -- closes the open file
end
-- next line is required to set permissions for open©&shift of the file
os.execute("chmod a+rw /home/pi/awekas_wl.html")
return commandArray
For upload to a remote server unfortunately no lua-scriptlines known to me, but a short python-script, to be periodically run as part of a cronjob.
Code: Select all
#!/usr/bin/python
# -*- coding = utf-8 to enable reading by simple editors -*-
# (c)2017 script compiled by Toulon7559 from various material from forums, version 0.2 for upload of awekas_wl.html
# --------------------------------------------------
# Line005 = PREPARATION & SETTING
# --------------------------------------------------
# Assure that ftplib has been installed, and make this script part of cronjob for periodic execution
# This script assumes the html-file to be saved to folder /home/pi/
# This script uploads the html-file to the root-folder of the remote ftp-server
# Lines 32 and 33 to be filled with YOUR applicable account-info for the ftp-account
# Line 34, 35, 37 and 38 inserted for change and reset of working directory for upload. Line-numbers and Print-lines are inserted for testing.
print
print ('Start of script')
# --------------------------------------------------
# Line016 = Function for FTP_UPLOAD to Server
# --------------------------------------------------
# Imports for script-operation
import ftplib
import os
# Definition of Upload_function
def upload(ftp, file):
ext = os.path.splitext(file)[1]
if ext in (".txt", ".htm", ".html"):
ftp.storlines("STOR " + file, open(file))
else:
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
# --------------------------------------------------
# Line030 = Actual FTP-Login & -Upload
# --------------------------------------------------
ftp = ftplib.FTP("<ftp_servername>")
ftp.login("<ftp_username>", "<ftp_password>")
# ftp.cwd('AWEKAS') # scriptline to select remote directory AWEKAS
# ftp.pwd() # return/check actual path
upload(ftp, "awekas_wl.html")
# ftp.cwd('/') # scriptline to reset to remote root-directory
# ftp.pwd() # return/check actual path
print ('End of script')