formatting MQTT message sensor lenght

135 views
Skip to first unread message

miso k

unread,
Apr 24, 2024, 4:15:18 PM4/24/24
to weewx-user
Hello Weather observers,

since long time my weewx server is running - and  updated to latest 5.0.2 version.

I want to export MQTT messages to Home Assistant, but the numbers are too long.
How can I make them shorter?
Example:
outHumidity = 91.0
inHumidity = 56.0
outTemp_C = 3.777777777777776
inTemp_C = 22.88888888888889
windSpeed_kph = 9.0123264
windGust_kph = 9.3341952


I have tried to format it through format = %.1f , but it does not seems to work

My MQTT Configuration:

[[MQTT]]
        server_url = mqtt://xxx:xxx@localhost:1883/
        topic = weather
        unit_system = METRIC
        binding = archive, loop
        aggregation = individual
        log_success = False
        log_failure = True
        [[[inputs]]]
            [[[[outTemp]]]]
                name = inside_temperature  # use a label other than outTemp
                format = %.1f              # two decimal places of precision
                unit = degree_F            # convert outTemp to F, others in C
            [[[[inTemp]]]]
                unit = degree_C                 # use F instead of C
                format = %.1f                   # use two decimal places of precision
                name = inside_temperature       # use label other than inTemp
            [[[[windSpeed]]]]
                units = meter_per_second        # use knots instead of meter_per_second
                format = %.1f                   # use two decimal places of precision
                name = wind_speed               # use label other than inTemp

Thank you!
Michal

michael.k...@gmx.at

unread,
Apr 24, 2024, 11:22:28 PM4/24/24
to weewx-user
What's the problem with the number of digits? Are they displayed correctly in HA? Or is there a problem for HA dealing with that number of digits generally?

Charlie Fortner

unread,
Apr 25, 2024, 9:53:14 AM4/25/24
to weewx...@googlegroups.com
On Wed, Apr 24, 2024, at 16:15, miso k wrote
I want to export MQTT messages to Home Assistant, but the numbers are too long.
How can I make them shorter?

I wouldn't do this with weewx, better to make the change in how Home Assistant displays the number. Via the GUI, find the device and change it's display precision settings. Here's an example:




Charlie

PS Sorry for the Home Assistant aside

Warren Gill

unread,
Apr 25, 2024, 10:22:30 AM4/25/24
to weewx...@googlegroups.com
Similarly I modify the sensors in home assistant with YAML:

################################################
#  Sensors
################################################
mqtt:
  sensor:
    - name: weewx_datetime
      state_topic: "weather/loop"
      value_template: |-
        {% if value_json.dateTime is defined  %}
          {{ value_json.dateTime | float }}
        {% endif %}

    - name: weewx_temperature
      state_topic: "weather/loop"
      unit_of_measurement: "°F"
      value_template: |-
        {% if value_json.outTemp_F is defined  %}
          {{ value_json.outTemp_F | round(1) }}
        {% endif %}


--
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 weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/f8b389a8-3d3b-4982-9967-1cd04a041190%40app.fastmail.com.

miso k

unread,
Apr 26, 2024, 1:27:21 PM4/26/24
to weewx-user
I have red on another forum, that the number is too big for HA to read it. Maybe I am wrong, but the possibilities that my configuration.yaml is wrong are limited already I hope

Dátum: štvrtok 25. apríla 2024, čas: 5:22:28 UTC+2, odosielateľ: michael.k...@gmx.at

miso k

unread,
Apr 26, 2024, 1:29:52 PM4/26/24
to weewx-user
I can read the MQTT message in HA built in MQTT plugin. So the server is correctly set up and MQTT client too. I can even read the messages in MQTT Explorer. 
The problem is, that the entity in HA is not updating and is "unknown". 

Dátum: piatok 26. apríla 2024, čas: 19:27:21 UTC+2, odosielateľ: miso k

miso k

unread,
Apr 26, 2024, 1:38:22 PM4/26/24
to weewx-user
finally... the name should not be in "" and it needs to be without space I hope. I am getting value updates now.

Thanks everyone for pointing me the right direction!

Dátum: piatok 26. apríla 2024, čas: 19:29:52 UTC+2, odosielateľ: miso k

vince

unread,
Apr 26, 2024, 1:45:42 PM4/26/24
to weewx-user
This works here with HA 2023.8 in a docker container:

  - name: "Outside"

    device_class: "temperature"

    state_topic: "vp2/loop"

    unit_of_measurement: '°F'

    value_template: "{{ value_json.outTemp | float | round(1) }}"



Reply all
Reply to author
Forward
0 new messages