Conversion unit in second data source

79 views
Skip to first unread message

flor...@pre-vost.fr

unread,
Sep 27, 2020, 12:33:49 PM9/27/20
to weewx-development
Hi, 

I work to implement a second data source with Netatmo Station and let the driver to the Davis Vantage Pro 2.

But the new StdService can't convert US unit to my database unit (Database is set to Metric). 
I've set this on the top of my py file but the conversion doesn't work : 

import weewx.units
from weewx.engine import StdService

weewx.units.obs_group_dict['windSpeedNetatmo'] = 'group_speed'
weewx.units.obs_group_dict['windGustNetatmo'] = 'group_speed'
weewx.units.obs_group_dict['rainNetatmo'] = 'group_rain'
weewx.units.obs_group_dict['windGustDirNetatmo'] = 'group_direction'
weewx.units.obs_group_dict['windDirNetatmo'] = 'group_direction'
weewx.units.obs_group_dict['barometerNetatmo'] = 'group_pressure'
weewx.units.obs_group_dict['outTempNetatmo'] = 'group_temperature'
weewx.units.obs_group_dict['datetimeNetatmo'] = 'group_time'

The StdService can convert unit or not ?

Thank's a lot. 


Tom Keffer

unread,
Sep 27, 2020, 9:12:03 PM9/27/20
to flor...@pre-vost.fr, weewx-development
I'm not sure what you mean by StdService. That's the abstract base class all the services inherit from.

In any case, if a service is to augment a record, it must check what unit system the incoming record is in, then convert what it is about to add to that unit system. There are many utilities in weewx.units for doing this. In particular, look at weewx.units.convertStd().  Also, look at ValueTuples, also to be found in weewx.units.

Say you are about to add a wind speed that is m/s. It would look something like this (NOT TESTED):

def new_archive_record(self, event):
    my_wind_speed =  (obtained from somewhere)
    # Create a Value Tuple:
    wind_speed_vt = weewx.units.ValueTuple(my_wind_speed, 'meter_per_second', 'group_speed')
    # Convert to the same unit system as the record
    wind_speed_converted_vt = weewx.units.convertStd(wind_speed_vt, event.record['usUnits'})
    # Put the converted value into the record:
    event.record['windSpeedNetatmo'] = wind_speed_converted_vt.value



--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/18d0423d-2722-46f3-a834-9516e3a008d0n%40googlegroups.com.

flor...@pre-vost.fr

unread,
Oct 2, 2020, 2:05:10 PM10/2/20
to weewx-development
Hi,
It work like a charm !

Just a last question. It is possible to capturing if the principal driver is in on new_archive_records ?
For example, if my driver get archive data or when I start a wee_reports, the driver checl also.
But for limited reach of Netatmo API set to 1000/j.
Reply all
Reply to author
Forward
0 new messages