You can configure the amount of decimal digits in skin.conf in section [Units], sub-section [[StringFormats]]. Add a line naming the unit and format string like this: degree_compass = %.3f.
Stefan Gliessmann schrieb am Freitag, 13. September 2024 um 14:59:09 UTC+2: > I have now made These changes in the Extensions.py file. > I now gut the unit correct to °, but have only integer values and no > digits after the decimal. > For the direction of a compass that is perfectly fine. For GPS coordinate, > no digits after the decimal is pretty useless for displaying purposes. > > As you can see, I tried to play arround with '%.3f', but that caused more > errors and weewx to exit ... > > So, how to I format the GPS coordinates with three digits after the > decimal, but keep the compass direction as an integer? > > # > # Copyright (c) 2009-2015 Tom Keffer <[email protected]> > # > # See the file LICENSE.txt for your full rights. > # > > """User extensions module > > This module is imported from the main executable, so anything put here > will be > executed before anything else happens. This makes it a good place to put > user > extensions. > """ > > import locale > import weewx.units > > # This sets the locale for all categories to the user’s default setting > (typically specified in the > # LANG environment variable). See: > https://docs.python.org/3/library/locale.html#locale.setlocale > locale.setlocale(locale.LC_ALL, '') > > import weewx.units ## works, but has no digits after the decimal > > for group in weewx.units.std_groups: > > weewx.units.std_groups[group].setdefault('group_coordinate','degree_compass') > weewx.units.obs_group_dict.setdefault('latitude','group_coordinate') > weewx.units.obs_group_dict.setdefault('longitude','group_coordinate') > > # Create a custom formatter for the latitude and longitude observations > #formatter = weewx.units.Formatter({'latitude': '%.3f', 'longitude': > '%.3f'}) > > # Set the formatter for the latitude and longitude observations > #weewx.units.obs_group_dict['latitude'] = ('degree_latitude', > 'group_coordinate', formatter) > #weewx.units.obs_group_dict['longitude'] = ('degree_longitude', > 'group_coordinate', formatter) > > > On Wednesday, August 21, 2024 at 4:13:51 PM UTC+2 Karen K wrote: > >> Each observation type needs an assignment to a unit group. So if you >> define a new observation type you have to write somewhere: >> >> >> weewx.units.obs_group_dict.setdefault('your_observation_type','group_something') >> >> The unit group must exist. group_direction is an example of a unit group >> that is connected to the unit degree_compass. >> >> Please also not the name of the unit degree_compass, not otherwise round. >> >> If you want to define a new unit group, say group_coordinate, you have >> to write: >> >> *for* group *in* weewx.units.std_groups: >> >> weewx.units.std_groups[group].setdefault('group_coordinate', >> 'degree_compass') >> >> You can include that code in user/extensions.py. >> >> >> Stefan Gliessmann schrieb am Mittwoch, 21. August 2024 um 15:46:28 UTC+2: >> >>> A GPS device in my RV sends the current coordinates via MQTT to my weewx >>> server. >>> The coordinates are displayed with units = None. >>> Trying to change them to units = degree_compass or units = " °" results >>> in the below error: >>> >>> Aug 21 15:28:26 rvwx weewx[1590] DEBUG weewx.units: Unable to convert >>> from None to ° >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: MQTT: Unexpected >>> exception of type <class 'KeyError'> >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** Traceback (most >>> recent call last): >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** File >>> "/usr/share/weewx/weewx/restx.py", line 382, in run_loop >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** >>> self.process_record(_record, dbmanager) >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** File >>> "/usr/share/weewx/user/mqtt.py", line 516, in process_record >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** data = >>> self.filter_data(record) >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** File >>> "/usr/share/weewx/user/mqtt.py", line 496, in filter_data >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** v = >>> weewx.units.convert(from_t, to_units)[0] >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** File >>> "/usr/share/weewx/weewx/units.py", line 1454, in convert >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** >>> conversion_func = conversionDict[val_t[1]][target_unit] >>> Aug 21 15:28:26 rvwx weewx[1590] ERROR weewx.restx: *** KeyError: None >>> Aug 21 15:28:26 rvwx weewx[1590] CRITICAL weewx.restx: MQTT: Thread >>> terminating. Reason: None >>> >>> Here is the relevant section from weewx.conf to display coordinates in >>> belchertown skin: >>> [[MQTT]] >>> server_url = mqtt:// >>> zzzz:[email protected]:1883/ >>> <http://zzzz:[email protected]:1883/> >>> topic = RV >>> unit_system = METRIC >>> binding = loop, archive >>> log_success = true >>> [[[inputs]]] >>> [[[[latitude]]]] >>> # units = " °" >>> format = %.3f >>> >>> and MQTT subscribe to Write the GPS data received via MQTT into the >>> weewx db: >>> [MQTTSubscribeService] >>> # This section is for the MQTTSubscribe service. >>> >>> # Turn the service on and off. >>> # Default is: true >>> # Only used by the service. >>> enable = true >>> log = true >>> >>> # The MQTT server. >>> # Default is localhost. >>> host = "wxvm.bz3gfkrlqtrsc3sv.myfritz.net" >>> >>> # The port to connect to. >>> # Default is 1883. >>> port = 1883 >>> >>> # Maximum period in seconds allowed between communications with the >>> broker. >>> # Default is 60. >>> keepalive = 60 >>> >>> # username for broker authentication. >>> # Default is None. >>> username = xxxx >>> >>> # password for broker authentication. >>> # Default is None. >>> password = yyyy >>> >>> # The binding, loop or archive. >>> # Default is: loop >>> # Only used by the service. >>> binding = loop >>> >>> # The message handler to use >>> [[message_callback]] >>> # The format of the MQTT payload. >>> # Currently support: individual, json, keyword >>> # Must be specified. >>> type = json >>> >>> # The topics to subscribe to. >>> [[topics]] >>> # Units for MQTT payloads without unit value. >>> # Valid values: US, METRIC, METRICWX >>> # Default is: US >>> unit_system = US >>> # adjust_start_time = 1 >>> use_server_datetime = True >>> use_topic_as_fieldname = true >>> >>> [[[RVGPS/#]]] >>> # The WeeWX name. >>> # Default is the name from MQTT. >>> #name = Latitude >>> >>> # True if the incoming data should not be processed into >>> WeeWX. >>> # Valid values: True, False >>> # Default is False >>> ignore = False >>> >>> # True if the incoming data is cumulative. >>> # Valid values: True, False >>> # Default is False >>> # contains_total = False >>> >>> # The conversion type necessary for WeeWX compatibility >>> # Valid values: bool, float, int, none >>> # Default is float >>> # conversion_type = int >>> >>> # The units of the incoming data. >>> # Useful if this field's units differ from the topic's >>> unit_system's units. >>> # Valid values: see, >>> http://www.weewx.com/docs/customizing.htm#units >>> # Default is not set >>> # units = degree_compass >>> >>> [image: Screenshot 2024-08-21 at 15.40.43.png] >>> >>> This is how it Looks on belchertown skin with units = None, e.g. no >>> change of units intented. >>> >>> TIA, >>> Stefan >>> >>> -- 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/ebb2e7c1-a818-4e3a-8809-93be15fe5185n%40googlegroups.com.
