After further experiments (see e.g.
this link), now the set of lua-script with related sh-files with RRDTool-application is 'Up & Running' at a Raspberry with Domoticz, related to a setup with Personal Weather Station type TFA_Nexus and a sensor type BMP180 hooked to the Raspberry.
Below are the 3 applicable software-files:
1) the sh-file generating the rrd-database-file
2) the sh-file generating the graph from the rrd-database-file
3) the lua-script extracting the data from Domoticz and controlling execution of the 2 sh-files, ultimately producing the graph.
For YOUR application obviously you have to adapt all file-names etc. according to YOUR configuration!
First you have to define what you want in the graph: that determines the minimum content and layout for the rdd-database-file.
The below setup is for the 'usual' 6 data-elements from a PWS, being temperature, humidty, pressure, wind speed and wind gust.
The numbers in the top-line and in the bottom-line define the layout of the RRA, and as consequence the layout of the graph.
Example-name (used in the lua-script!) of this file is create_pimeteo2_rrd.sh
Must be executable, therefore set properties to 755
Run this rrd-creation-file from the command line of the Raspberry.
That produces the basic rrd-file with the name in the second scriptline in directory /home/pi/
Code: Select all
#!/bin/bash
/usr/bin/rrdtool create /home/pi/pimeteo2.rrd --start N --step 300 \
DS:Temp1:GAUGE:600:U:U \
DS:Humid1:GAUGE:600:U:U \
DS:Baro1:GAUGE:600:U:U \
DS:RainD:GAUGE:600:U:U \
DS:WindS:GAUGE:600:U:U \
DS:WindG:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:3000
Second you have to make the sh-file for generation of the graph from the rrd-file.
Example-name (used in the lua-script!) is create_pimeteo2A_graph.sh
Also this file must be executable, therefore set properties to 755
In this script I solved the 'characteristic' of RDDTool of having only 1 Y-axis by
- deduction of 1000 from the pressure-value, resulting of effective scale-values between -30 and +30
- multiplication of wind-values by 10, putting them upto approx 70 for windspeed of 7m/s
Code: Select all
#!/bin/bash
rrdtool graph /home/pi/pimeteo2.png \
DEF:temp=/home/pi/pimeteo2.rrd:Temp1:AVERAGE \
DEF:humid=/home/pi/pimeteo2.rrd:Humid1:AVERAGE \
DEF:press=/home/pi/pimeteo2.rrd:Baro1:AVERAGE \
DEF:raind=/home/pi/pimeteo2.rrd:RainD:AVERAGE \
DEF:winds=/home/pi/pimeteo2.rrd:WindS:AVERAGE \
DEF:windg=/home/pi/pimeteo2.rrd:WindG:AVERAGE \
CDEF:press2=press,1000,- \
CDEF:winds2=winds,10,* \
CDEF:windg2=windg,10,* \
LINE1:temp#ff0000:Temperature \
LINE1:humid#0000ff:Humidity \
LINE1:press2#5fd00b:Pressure \
LINE1:raind#00ffff:Rain_today \
LINE1:winds2#000000:Windspeed \
LINE1:windg2#871f78:Windgust \
COMMENT:"\t\t\t\t\t\t\l" \
COMMENT:"\t\t\t\t\t\t\l" \
GPRINT:temp:LAST:"Temperature Latest\: %2.1lf" \
GPRINT:temp:MAX:" Max.\: %2.1lf" \
GPRINT:temp:MIN:" Min.\: %2.1lf" \
COMMENT:"\t\t\t\t\t\t\l" \
GPRINT:humid:LAST:"Humidity Latest\: %2.1lf" \
GPRINT:humid:MAX:" Max.\: %2.1lf" \
GPRINT:humid:MIN:" Min.\: %2.1lf" \
COMMENT:"\t\t\t\t\t\t\l" \
GPRINT:press:LAST:"Pressure Latest\: %2.1lf" \
GPRINT:press:MAX:" Max.\: %2.1lf" \
GPRINT:press:MIN:" Min.\: %2.1lf" \
COMMENT:"\t\t\t\t\t\t\l" \
GPRINT:raind:LAST:"Rain_today Latest\: %2.1lf" \
GPRINT:raind:MAX:" Max.\: %2.1lf" \
GPRINT:raind:MIN:" Min.\: %2.1lf" \
COMMENT:"\t\t\t\t\t\t\l" \
GPRINT:winds:LAST:"Windspeed Latest\: %2.1lf" \
GPRINT:winds:MAX:" Max.\: %2.1lf" \
GPRINT:winds:MIN:" Min.\: %2.1lf" \
COMMENT:"\t\t\t\t\t\t\l" \
GPRINT:windg:LAST:"Windgust Latest\: %2.1lf" \
GPRINT:windg:MAX:" Max.\: %2.1lf" \
GPRINT:windg:MIN:" Min.\: %2.1lf" \
COMMENT:"\t\t\t\t\t\t\l" \
--width 700 --height 400 \
--title="Temperature, Humidity, Pressure, Rain & Wind for last 24 hour" \
--vertical-label="Temp.(C)/Hum.(%)/Baro(hPa,-1000)/Rain(mm)/Wind(m/s,*10)" \
--watermark "`date`"
# Copy picture to directory of local website
# cp /home/pi/pimeteo2.png /var/www/html
Finally the lua-script as required to link everything, which I called script_time_meteo2_fill_rrd_database_graph.lua, has following steps:
1) define the inputs
2) define the interval for graphing
3) extract, process & correct values, as required
4) put the values in a list with understandable and
compatible labels as inputs for the rdd-file
5) update the rrd-file
6) perform graphing at the defined interval
Products of the lua-script are an updated rrd-file and a related png-file in directory /home/pi/
If you want to apply that png-file elsewhere, you need to copy or upload that file.
The sh-file for graphic_output ends with a copy-instruction, but unfortunately (in my setup) it reports an error, to

be solved by you ....
For upload I apply a python-script or sync-software which 'grasps' the png-file.
As usual for my lua-scripts with line-numbers, print-lines and comments, which you might delete.
Code: Select all
------------------------------------------------------------------------------
-- Version 01C 20171111
--
-- Domoticz lua script to put values from Domoticz to RRD_Database.
-- Extracts the contents based on the unique names of items, passes them
-- to the designated RRD_Database and generates a graph from selected data.
-- This version for collected, basic Meteo-info from TFA_Nexus & BMP180.
-- Relative to the setup described in ct2017#5, this script
-- within the lua-script updates the database and generates the graph,
-- by calling sh-files through os.execute
------------------------------------------------------------------------------
-- Source-info from ct2017,#5 + Domoticz-forum, adapted by Toulon7559 (c)2017
------------------------------------------------------------------------------
print ('Start of meteo2 rrd-script 1C')
-- Line 15, Definition of Inputs
Outside_Temp_Hum = 'TFA1_Temp_RV_Hoog'
Barometer = 'BMP180_Temp_Baro'
RainMeter = 'TFA_Nexus_Neerslag'
WindMeter = 'TFA_Nexus_Wind'
-- Line 19, Settings
-- Intervals
Interval1 = 15; Offset1 = 1 -- Time in minutes to run create_rrd_graph
-- Line 23, Local Functions
local function Round(num, idp)
return tonumber(string.format("%." ..(idp or 0).. "f", num))
end
-- Line 29, Data Extraction from Domoticz'svalues for TFA_Nexus
sTempTFA, sRVTFA = otherdevices_svalues[Outside_Temp_Hum]:match("([^;]+);([^;]+)")
sTempTFA = tonumber(sTempTFA);
sRVTFA = tonumber(sRVTFA);
-- Line 33 Data Extraction from Domoticz'svalues for BMP180
sBMP180T, sBMP180B = otherdevices_svalues[Barometer]:match("([^;]+);([^;]+)")
sBMP180T = tonumber(sBMP180T); -- Temperature at BMP180-sensor
sBMP180B = tonumber(sBMP180B); -- Pressure at BMP180-sensor
print ('BMP180_druk_raw = '.. sBMP180B)
-- Line 38, Checkline Outside_Temp_Hum
if Outside_Temp_Hum ~= '' then
TempOut1 = sTempTFA
HumOut1 = sRVTFA
end
-- Line 43, Checkline Barometer & Correction & Offset
a = 1 -- relative correction for air pressure in hPa, default is 1, range from 0.9 to 1.1 for max. 10% offset
b = 0 -- absolute correction for air pressure in hPa, default is 0, practical range from -10 to +10
if Barometer ~= '' then
sBMP180B = a*sBMP180B + b
print ('BMP180_corrected = '.. sBMP180B)
PressOut1 = sBMP180B
print ('BMP180_offset = '.. sBMP180B)
end
-- Line 52, Checkline for Rain-info
if RainMeter ~= '' then
Rain_Day = otherdevices_rain[RainMeter]
Rain_hour = otherdevices_rain_lasthour[RainMeter]
end
-- Line 57, Checkline for Wind-info
if WindMeter ~= '' then
Winddir = otherdevices_winddir[WindMeter]
Windspeedmps = otherdevices_windspeed[WindMeter]
Windgustmps = otherdevices_windgust[WindMeter]
end
commandArray = {}
-- Line 66, Compilation & Print Temp&Hum&Baro
Temp1 = Round(TempOut1, 2); print ('Temp = '..Temp1) -- Outside temperature
Humid1 = Round(HumOut1, 2); print ('Humid = '..Humid1) -- Outside humidity
Baro1 = Round(PressOut1, 2); print ('Baro = '..Baro1) -- Barometric pressure
RainD = Round(Rain_Day, 2); print ('RainD = '..RainD) -- Rain today
-- RainH = Round(Rain_Hour, 2); print ('RainH = '..RainH) -- Rain last hour
-- WindD = Round(Winddir, 2); print ('WindD = '..WindD) -- Wind Direction
WindS = Round(Windspeedmps, 2); print ('WindS = '..WindS) -- Wind speed
WindG = Round(Windgustmps, 2); print ('WindG = '..WindG) -- Wind gust
-- Line 76, Export of data = update of rrd database(s) and generation of graph
-- Line 77, Extract current date as date.year, date.month, date.day, date.hour, date.min, date.sec
date = os.date("*t")
-- Line 79, Update of rrd database
-- RRD has internal setting for expecting update once per 5 minutes
os.execute ('rrdtool update /home/pi/pimeteo2.rrd N:'..Temp1..':'..Humid1..':'..Baro1..':'..RainD..':'..WindS..':'..WindG)
print ('RRD, Database updated!')
-- end
-- Line 84, Generation of graph
-- if (date.min % Interval1 == Offset1) then
os.execute ('sudo /home/pi/create_pimeteo2A_graph.sh')
-- next line is required to set rw-permissions at all levels for open©&shift of the output-file
-- os.execute("chmod a+rw /home/pi/pimeteo2.png")
print ('RRD, Graph generated!')
-- end
print ('End of meteo2 rrd-script 1C')
return commandArray