The last version of the file is attached.
There is something added to use the data within a binding.
Karen K schrieb am Sonntag, 7. Februar 2021 um 12:05:57 UTC+1:
> I extended the file by trend values. Look at the new file attached, please.
>
> [email protected] schrieb am Donnerstag, 28. Januar 2021 um 23:45:17
> UTC+1:
>
>> Thanks, that is exactly what I was looking for. I know it is too late for
>> you, but I thought other people might need to add units, unit groups, and
>> observations. So, I was looking for a real world example. I’ve opened issue
>> 118 <https://github.com/bellrichm/WeeWX-MQTTSubscribe/issues/118> to
>> work on this in MQTTSubscribe.
>>
>> On Thursday, 28 January 2021 at 15:03:22 UTC-5 [email protected] wrote:
>>
>>> I am not sure that I understood what I am expected to post. The units
>>> and unit group definition file I created is this:
>>>
>>> [email protected] schrieb am Montag, 25. Januar 2021 um 01:09:55 UTC+1:
>>>
>>>> Karen,
>>>> If you pst what you have done, I’d be willing to look at updating
>>>> MQTTSubscribe to have a configuration option. If we get something working,
>>>> perhaps a pull request to WeeWX might result.
>>>> rich
>>>>
>>>> On Sunday, 24 January 2021 at 05:57:47 UTC-5 [email protected] wrote:
>>>>
>>>>> @Rich: Yes, I was afraid that that is the only way to do it. So I
>>>>> guess, I will do it the same way
>>>>>
>>>>> @Weatherl: Oh, I did not install devices of my own. Instead I got
>>>>> permission to read the readings of the official level and flow meters
>>>>> from
>>>>> the government. They provide an API in the Internet here. If you register
>>>>> with them you can get the data live.
>>>>>
>>>>> [email protected] schrieb am Samstag, 23. Januar 2021 um 22:48:32
>>>>> UTC+1:
>>>>>
>>>>>> I'll be interested in hearing if there is a better way, but here is
>>>>>> what I did to add a new observation.
>>>>>> 1. Wrote this service.
>>>>>>
>>>>>> import weewx
>>>>>>
>>>>>> import weewx.units
>>>>>> weewx.units.obs_group_dict['honeywell01'] = 'group_temperature'
>>>>>> weewx.units.obs_group_dict['honeywell02'] = 'group_temperature'
>>>>>> weewx.units.obs_group_dict['honeywell03'] = 'group_temperature'
>>>>>>
>>>>>> class Noop(weewx.engine.StdService):
>>>>>> pass
>>>>>>
>>>>>> 2. Updated weewx.conf
>>>>>> prep_services = weewx.engine.StdTimeSynch ,
>>>>>> user.bellrichm.Noop
>>>>>>
>>>>>> rich
>>>>>>
>>>>>> On Saturday, 23 January 2021 at 16:18:28 UTC-5 [email protected]
>>>>>> wrote:
>>>>>>
>>>>>>> I installed MQTTSubscribe service. In this case it provides data
>>>>>>> about water level (unit cm) and water flow (unit cubic meter per
>>>>>>> second) of
>>>>>>> the near river.
>>>>>>>
>>>>>>> As those units and unit group are not included in the standard weewx
>>>>>>> I have to assign them elsewhere.
>>>>>>>
>>>>>>> Because I use the MQTTSubscribe service, there is no need to write
>>>>>>> an extension. On the other hand, no extension file means no place to
>>>>>>> put
>>>>>>> the assignment of the additional units and unit groups.
>>>>>>>
>>>>>>> Could I declare those units and unit groups somewhere in weewx.conf?
>>>>>>>
>>>>>>> Is there any other possibility?
>>>>>>>
>>>>>>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/db5629a9-85e5-473c-93a9-6f1d83eccd19n%40googlegroups.com.
# water level and water flow units and unit groups
# Copyright (c) 2021 Johanna Roedenbeck
"""
value US METRIC & METRICWX
-------------------------------------------------------
water level W ft cm
water level trend ft/h cm/h
water flow Q ft^3/s m^3/s
water flow trend ft^3/s/h m^3/s/h
"""
# import units module to extend group, units, and conversion tables
import weewx.units
# for extend() function
import weeutil.weeutil
# if MQTT export extension is installed, include unit label reduction
try:
import user.mqtt
hasMQTT=True
except ImportError:
hasMQTT=False
# add groups for water level and water flow
weewx.units.USUnits.extend(
{'group_flow':'ft3ps', # cubic foot per second
'group_flow_trend':'ft3psph',
'group_level':'foot',
'group_level_trend':'foot_per_hour'})
# add groups for water level and water flow
weewx.units.MetricUnits.extend(
{'group_flow':'m3ps', # cubic meter per second
'group_flow_trend':'m3psph',
'group_level':'cm',
'group_level_trend':'cm_per_hour'})
# add groups for water level and water flow
weewx.units.MetricWXUnits.extend(
{'group_flow':'m3ps', # cubic meter per second
'group_flow_trend':'m3psph',
'group_level':'cm',
'group_level_trend':'cm_per_hour'})
# default format for flow units
weewx.units.default_unit_format_dict['m3ps']='%.1f'
weewx.units.default_unit_format_dict['m3psph']='%.2f'
weewx.units.default_unit_format_dict['ft3ps']='%.0f'
# default unit label for flow units
weewx.units.default_unit_label_dict['m3ps']=u" m³/s"
weewx.units.default_unit_label_dict['m3psph']=u" m³/s/h"
weewx.units.default_unit_label_dict['ft3ps']=u" ft³/s"
# Note: default format and unit labels for water level units are
# already defined within weewx.units. No need to do it here.
# add conversion functions between cm and foot for water level
weewx.units.conversionDict['cm']['foot']= lambda x : x / 30.48
weewx.units.conversionDict['foot']['cm']= lambda x : x * 30.48
# add conversion functions between cm/h and ft/h for water level trend
if 'cm_per_hour' not in weewx.units.conversionDict:
weewx.units.conversionDict['cm_per_hour']={'foot_per_hour': lambda x : x / 30.48 }
else:
weewx.units.conversionDict['cm_per_hour']['foot_per_hour']= lambda x : x / 30.48
if 'foot_per_hour' not in weewx.units.conversionDict:
weewx.units.conversionDict['foot_per_hour']={'cm_per_hour': lambda x : x * 30.48 }
else:
weewx.units.conversionDict['foot_per_hour']['cm_per_hour']= lambda x : x * 30.48
# add conversion functions for flow units
if 'm3ps' not in weewx.units.conversionDict:
weewx.units.conversionDict['m3ps']={'ft3ps': lambda x : x * 35.3147 }
else:
weewx.units.conversionDict['m3ps']['ft3ps']= lambda x : x * 35.3147
if 'ft3ps' not in weewx.units.conversionDict:
weewx.units.conversionDict['ft3ps']={'m3ps': lambda x : x / 35.3147 }
else:
weewx.units.conversionDict['ft3ps']['m3ps']= lambda x : x / 35.3147
# add conversion functions for flow trend units
if 'm3psph' not in weewx.units.conversionDict:
weewx.units.conversionDict['m3psph']={'ft3psph': lambda x : x * 35.3147 }
else:
weewx.units.conversionDict['m3psph']['ft3psph']= lambda x : x * 35.3147
if 'ft3psph' not in weewx.units.conversionDict:
weewx.units.conversionDict['ft3psph']={'m3psph': lambda x : x / 35.3147 }
else:
weewx.units.conversionDict['ft3psph']['m3psph']= lambda x : x / 35.3147
if hasMQTT:
if 'cm_per_hour' not in user.mqtt.UNIT_REDUCTIONS:
user.mqtt.UNIT_REDUCTIONS['cm_per_hour']='cmph'
if 'foot_per_hour' not in user.mqtt.UNIT_REDUCTIONS:
user.mqtt.UNIT_REDUCTIONS['foot_per_hour']='ftph'
# water level and flow measurements
weewx.units.obs_group_dict.extend(
{'Q566055v':'group_flow',
'Q566055t':'group_flow_trend',
'W566055v':'group_level',
'W566055t':'group_level_trend',
'W566055a':'group_count',
'Q567470v':'group_flow',
'Q567470t':'group_flow_trend',
'W567470v':'group_level',
'W567470t':'group_level_trend',
'W567470a':'group_count'})
# database schema
pegelTable = [
('dateTime','INTEGER NOT NULL PRIMARY KEY'),
('usUnits','INTEGER NOT NULL'),
('interval','INTEGER NOT NULL'),
('W566055v','REAL'),
('W566055s','VARCHAR(10)'),
('W566055a','INTEGER'),
('Q566055v','REAL'),
('Q566055s','VARCHAR(10)'),
('Q566055a','INTEGER'),
('W567470v','REAL'),
('W567470s','VARCHAR(10)'),
('W567470a','INTEGER'),
('Q567470v','REAL'),
('Q567470s','VARCHAR(10)'),
('Q567470a','INTEGER')]
pegel_day_summaries = [(e[0], 'scalar') for e in pegelTable
if e[0] not in ('dateTime', 'usUnits', 'interval')]
pegelSchema = {
'table': pegelTable,
'day_summaries' : pegel_day_summaries
}
class Noop(weewx.engine.StdService):
pass