Displaying a current obs value on a page/in a report merely needs us to add the obs to the loop packets and/or archive records generated
by WeeWX. For density altitude this would be best done by writing a
custom service that adds density altitude to the WeeWX generated loop
packets. WeeWX will then accumulate the density altitude data over an
archive period and include density altitude in the WeeWX generated
archive record. It won't be saved to the database but it will allow you
to use the current value (using the tag $current.densityAltitude - assumes the density altitude data observation is named densityAltitude)
in a WeeWX generated report. To be able to plot density altitude or
include aggregates such as min/max etc you need to save density altitude
to the database. This can be done in a number of ways but is best done
by customizing the WeeWX database schema.import weewx
from weewx.engine import StdService
class DensityAltitude(StdService):
def __init__(self, engine, config_dict):
# Initialize my superclass first:
super(DensityAltitude, self).__init__(engine, config_dict)
# Bind to any new archive record events:
self.bind(weewx.NEW_LOOP_PACKET, self.new_loop_packet)
self.last_total = None
def new_loop_packet(self, event):
if 'outTemp' in event.packet and 'outHumidity' in event.packet:
try:
da = event.packet['outTemp'] + 2.0 * event.packet['outHumidity']
except TypeError:
da = None
event.packet['densityAltitude'] = da
[Engine]
[[Services]]
# This section specifies the services that should be run. They are
# grouped by type, and the order of services within each group
# determines the order in which the services will be run.
prep_services = weewx.engine.StdTimeSynch
data_services = user.da.DensityAltitude
process_services = weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate
archive_services = weewx.engine.StdArchive
restful_services = weewx.restx.StdStationRegistry, weewx.restx.StdWunderground, weewx.restx.StdPWSweather, weewx.restx.StdCWOP, weewx.restx.StdWOW, weewx.restx.StdAWEKAS
report_services = weewx.engine.StdPrint, weewx.engine.StdReport
def new_loop_packet(self, event):
if 'pressure' in event.packet :
try:
altitude_metric = 1326 # Need to get the '$Station.altitude' value (in meter) but how ?
abspr = 100 * (event.packet['pressure'] * (1 - (0.0065 * altitude_metric / 288.15)) ** 5.255)
except TypeError:
abspr = None
event.packet['abspressure'] = abspr
altitude_metric = weewx.units.convert(engine.stn_info.altitude_vt, 'meter').valueimport weewx.unitsaltitude_metric = weewx.units.convert(self.engine.stn_info.altitude_vt, 'meter').value
pressure = hardware
barometer = hardware
altimeter = hardwareREC: 2020-06-09 01:10:00 CEST (1591657800) abspressure: 86243.0903176, appTemp: 3.58493191965, cloudbase: 1383.6687016, dateTime: 1591657800, density: 1.0759016949, dewpoint: 5.6507119535, ET: None, heatindex: 6.09090909091, humidex: 6.09090909091, inDewpoint: 7.58780896445, inHumidity: 56.0, inTemp: 16.3909090909, inTempBatteryStatus: 0.0, interval: 5, maxSolarRad: 0.0, outHumidity: 97.0, outTemp: 6.09090909091, outTempBatteryStatus: 0.0, pressure: 1012.14545455, rain: 0.258, rainBatteryStatus: 0.0, rainRate: 1.19545454545, rxCheckPercent: 100.0, usUnits: 17, windBatteryStatus: 0.0, windchill: 6.09090909091, windDir: 18.6782954436, windGust: 4.90000000392, windGustDir: 22.5, windrun: 0.64909090961, windSpeed: 2.16363636537
LOOP: 2020-06-09 01:10:56 CEST (1591657856) abspressure: 86247.7380374, appTemp: 3.2397243331, cloudbase: 1383.62871855, dateTime: 1591657856, density: 1.07631006422, dewpoint: 5.56013080839, heatindex: 6.0, humidex: 6.0, inDewpoint: 7.59628096224, inHumidity: 56, inTemp: 16.4, inTempBatteryStatus: 0, maxSolarRad: 0.0, outHumidity: 97, outTemp: 6.0, outTempBatteryStatus: 0, pressure: 1012.2, rain: 0.0, rainBatteryStatus: 0, rainRate: 1.29, rxCheckPercent: 100, usUnits: 17, windBatteryStatus: 0, windchill: 6.0, windDir: 22.5, windGust: 3.10000000248, windGustDir: 22.5, windSpeed: 2.500000002Regarding the 2nd part of your answer / question, I'm using a LaCrosse WS2812 station (ws28xx driver), with this setting in weewx.conf :pressure = hardware
barometer = hardware
altimeter = hardware
I get these outputs in the log:REC: 2020-06-09 01:10:00 CEST (1591657800) abspressure: 86243.0903176, appTemp: 3.58493191965, cloudbase: 1383.6687016, dateTime: 1591657800, density: 1.0759016949, dewpoint: 5.6507119535, ET: None, heatindex: 6.09090909091, humidex: 6.09090909091, inDewpoint: 7.58780896445, inHumidity: 56.0, inTemp: 16.3909090909, inTempBatteryStatus: 0.0, interval: 5, maxSolarRad: 0.0, outHumidity: 97.0, outTemp: 6.09090909091, outTempBatteryStatus: 0.0, pressure: 1012.14545455, rain: 0.258, rainBatteryStatus: 0.0, rainRate: 1.19545454545, rxCheckPercent: 100.0, usUnits: 17, windBatteryStatus: 0.0, windchill: 6.09090909091, windDir: 18.6782954436, windGust: 4.90000000392, windGustDir: 22.5, windrun: 0.64909090961, windSpeed: 2.16363636537
LOOP: 2020-06-09 01:10:56 CEST (1591657856) abspressure: 86247.7380374, appTemp: 3.2397243331, cloudbase: 1383.62871855, dateTime: 1591657856, density: 1.07631006422, dewpoint: 5.56013080839, heatindex: 6.0, humidex: 6.0, inDewpoint: 7.59628096224, inHumidity: 56, inTemp: 16.4, inTempBatteryStatus: 0, maxSolarRad: 0.0, outHumidity: 97, outTemp: 6.0, outTempBatteryStatus: 0, pressure: 1012.2, rain: 0.0, rainBatteryStatus: 0, rainRate: 1.29, rxCheckPercent: 100, usUnits: 17, windBatteryStatus: 0, windchill: 6.0, windDir: 22.5, windGust: 3.10000000248, windGustDir: 22.5, windSpeed: 2.500000002=> 'pressure' (REC:1012.14 & LOOP:1012.2) is wrong : due to station altitude being at 1330 meter, absolute pressure should be around the 860-865hPa mark. And as it's probably temperature compensated by the hardware (not explicitly written in the LaCrosse datasheet), it should then be called 'barometer' in WeeWX language.
=> 'barometer' is NOT provided by hardware.=> 'altimeter' is NOT provided by hardware.So, YES the hardware is emiting the 'pressure' instead of the 'barometer' value. Of course I also tried other settings in the .conf file, all without success, 'pressure' always being the only usable value ('barometer' and 'altimeter' went either missing or wrong).
[StdCalibrate]
barometer = pressure
pressure = None[StdWXCalculate]
....
[[Calculations]]
pressure = prefer_hardware
altimeter = prefer_hardware