WeeWX, MQTT and how to import Data

Ladies, Gents,

i´m not a newbee, but 52 y old and not a skilled mqtt pro.
system: raspi 3b+ with 120gb ssd: hass core 0.112.2 OS 4.10 mosquitto broker
weewx on another raspi.

currently i´m asking the weewx server via mqtt broker for new weather data. log:

1594996516: New connection from 192.168.0.15 on port 1883.
1594996516: New client connected from 192.168.0.15 as weewx_36f5aed1 (p2, c1, k60, u’xxxxxxx’).
1594996517: Client weewx_36f5aed1 disconnected.
1594996593: Saving in-memory database to /data/mosquitto.db.
1594996816: New connection from 192.168.0.15 on port 1883.
[INFO] found xxxxxxx on local database
1594996817: New client connected from 192.168.0.15 as weewx_2c1ea416 (p2, c1, k60, u’xxxxxxx’).
1594996818: Client weewx_2c1ea416 disconnected.
1594997119: New connection from 192.168.0.15 on port 1883.
[INFO] found xxxxxxx on local database
1594997120: New client connected from 192.168.0.15 as weewx_d92fbd1c (p2, c1, k60, u’xxxxxxx’).
1594997121: Client weewx_d92fbd1c disconnected.

so far, so good, but where are the data? how can i integrate the data into hass.io?
i´ve checked with the mqtt explorer, if there are the data and voila
mqtt

ok, but how to subscribe the wx-variables and how can i integrate them?

any help is very appreciated,
greez michl

Use the MQTT sensor.

1 Like

Great! Thank you @Burningstone!

temp

Is there a way to reduce the number of decimals?

You can round the result in the value_template part of the sensor. Can you show your current working code please?

1 Like

this is the part from configuration.yaml

mqtt sensor

sensor:
- platform: mqtt
name: “OutTemperature1”
state_topic: “weather/outTemp_C”
unit_of_measurement: ‘°C’

Please read this topic, especially point 11 regarding the correct formatting of code in the forum.

You can use a value_template to round your value.

Try this:

sensor:
  - platform: mqtt
    name: “OutTemperature1”
    state_topic: “weather/outTemp_C”
    unit_of_measurement: ‘°C’
    value_template: "{{ (value | round(2)) | float }}"

I’m not sure if the last float filter is needed, you can probably remove it, can’t test at the moment.

2 Likes

Thank you @Burningstone for help and hints regarding correct formatting.
and no problem, i´ll play around and will inform if this thing works.

works like a charme.
thp-display

i had to adapt the quotation marks and reduced to 1 decimal, now this is working fine:

sensor:
    - platform: mqtt
      name: "OutTemperature_101"
      state_topic: "weather/outTemp_C"
      unit_of_measurement: '°C'
      value_template: "{{ (value | round(1)) | float }}"

Thx for helping a silversurfer :wink:

Posting a complete list of weewx entities here to make it easier for others.
Enjoy!

mqtt:
  sensor:
    - name: weather_station_outtemp_c
      unique_id: uniqueid__weather_outtemp_c
      icon: mdi:thermometer
      state_topic: "weather/outTemp_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    - name: weather_station_intemp_c
      unique_id: uniqueid__weather_intemp_c
      icon: mdi:thermometer
      state_topic: "weather/inTemp_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    - name: weather_station_dewpoint_c
      unique_id: uniqueid__weather_dewpoint_c
      icon: mdi:thermometer
      state_topic: "weather/dewpoint_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    - name: weather_station_indewpoint_c
      unique_id: uniqueid__weather_indewpoint_c
      icon: mdi:thermometer
      state_topic: "weather/inDewpoint_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    - name: weather_station_windchill_c
      unique_id: uniqueid__weather_windchill_c
      icon: mdi:thermometer
      state_topic: "weather/windchill_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    - name: weather_station_apptemp_c
      unique_id: uniqueid__weather_apptemp_c
      icon: mdi:thermometer
      state_topic: "weather/appTemp_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    - name: weather_station_heatindex_c
      unique_id: uniqueid__weather_geatindex_c
      icon: mdi:thermometer
      state_topic: "weather/heatindex_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    - name: weather_station_humidex_c
      unique_id: uniqueid__weather_humindex_c
      icon: mdi:thermometer
      state_topic: "weather/humidex_C"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°C"
      device_class: temperature

    #############################################################################

    - name: weather_station_outhumidity
      unique_id: uniqueid__weather_outhumidity
      icon: mdi:water-percent
      state_topic: "weather/outHumidity"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "%"
      device_class: humidity

    - name: weather_station_inhumidity
      unique_id: uniqueid__weather_inhumidity
      icon: mdi:water-percent
      state_topic: "weather/inHumidity"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "%"
      device_class: humidity

    - name: weather_station_altimeter_mbar
      unique_id: uniqueid__weather_altimeter_atmospheric
      icon: mdi:gauge
      state_topic: "weather/altimeter_mbar"
      value_template: "{{ value | round(0) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mbar"
      device_class: atmospheric_pressure

    - name: weather_station_pressure_mbar
      unique_id: uniqueid__weather_pressure_atmospheric
      icon: mdi:gauge
      state_topic: "weather/pressure_mbar"
      value_template: "{{ value | round(0) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mbar"
      device_class: atmospheric_pressure

    - name: weather_station_barometer_mbar
      unique_id: uniqueid__weather_barometer_atmospheric
      icon: mdi:gauge
      state_topic: "weather/barometer_mbar"
      value_template: "{{ value | round(0) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mbar"
      device_class: atmospheric_pressure

    #############################################################################
    - name: weather_station_windspeed_kph
      unique_id: uniqueid__weather_windspeed_kph
      icon: mdi:weather-windy
      state_topic: "weather/windSpeed_kph"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "km/h"
      device_class: wind_speed

    - name: weather_station_windgust_kph
      unique_id: uniqueid__weather_windgust_kph
      icon: mdi:weather-windy-variant
      state_topic: "weather/windGust_kph"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "km/h"
      device_class: wind_speed

    - name: weather_station_winddir
      unique_id: uniqueid__weather_winddir
      icon: mdi:wind-turbine
      state_topic: "weather/windDir"
      value_template: "{{ value | round(0) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°"

    - name: weather_station_windgustdir
      unique_id: uniqueid__weather_windgustdir
      icon: mdi:wind-turbine
      state_topic: "weather/windGustDir"
      value_template: "{{ value | round(0) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "°"

    - name: weather_station_windrun_km
      unique_id: uniqueid__weather_windrun_km
      icon: mdi:wind-turbine
      state_topic: "weather/windrun_km"
      value_template: "{{ value | round(3) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "km"
      device_class: distance

    - name: weather_station_rainrate_mm_per_hour
      unique_id: uniqueid__weather_rainrate_mm_per_hour
      icon: mdi:umbrella-outline
      state_topic: "weather/rainRate_cm_per_hour"
      value_template: "{{ (value | float * 10) | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mm/h"
      device_class: precipitation_intensity

    - name: weather_station_rain_mm
      unique_id: uniqueid__weather_rain_mm
      icon: mdi:umbrella
      state_topic: "weather/rain_cm"
      value_template: "{{ (value | float * 10) | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mm"
      device_class: precipitation
      force_update: true # important!

    - name: weather_station_rain24_mm
      unique_id: uniqueid__weather_rain24_mm
      icon: mdi:umbrella
      state_topic: "weather/rain24_cm"
      value_template: "{{ (value | float * 10) | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mm"
      device_class: precipitation

    - name: weather_station_hourrain_mm
      unique_id: uniqueid__weather_hourrain_mm
      icon: mdi:umbrella
      state_topic: "weather/hourRain_cm"
      value_template: "{{ (value | float * 10) | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mm"
      device_class: precipitation

    - name: weather_station_dayrain_mm
      unique_id: uniqueid__weather_dayrain_mm
      icon: mdi:umbrella
      state_topic: "weather/dayRain_cm"
      value_template: "{{ (value | float * 10) | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mm"
      device_class: precipitation

    - name: weather_station_evapotranspiration_mm
      unique_id: uniqueid__evapotranspiration_mm
      icon: mdi:water-opacity
      state_topic: "weather/ET_cm"
      value_template: "{{ (value | float * 10) | round(5) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "mm"
      device_class: precipitation
      force_update: true # important!

    #############################################################################

    - name: weather_station_radiation_wpm2
      unique_id: uniqueid__weather_radiation_irradiance
      icon: mdi:radioactive
      state_topic: "weather/radiation_Wpm2"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "W/m²"
      device_class: irradiance

    - name: weather_station_maxsolarrad_wpm2
      unique_id: uniqueid__weather_maxsolarrad_irradiance
      icon: mdi:radioactive
      state_topic: "weather/maxSolarRad_Wpm2"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "W/m²"
      device_class: irradiance

    - name: weather_station_cloudbase_meter
      unique_id: uniqueid__weather_cloudbase_distance
      state_topic: "weather/cloudbase_meter"
      value_template: "{{ value | round(0) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: "m"
      device_class: distance

    - name: weather_station_uv
      unique_id: uniqueid__weather_uv
      icon: mdi:sunglasses
      state_topic: "weather/UV"
      value_template: "{{ value | round(1) }}"
      availability_topic: "weather/availability"
      unit_of_measurement: ""

    #############################################################################

    - name: weather_station_weewx_update_datetime
      unique_id: uniqueid__weather_datetime
      icon: mdi:calendar-clock
      state_topic: "weather/dateTime"
      value_template: "{{ value | int | timestamp_local() }}"
      availability_topic: "weather/availability"
      device_class: timestamp

template:
  - binary_sensor:
      - name: weather_station_weewx_connected
        unique_id: uniqueid__weather_connected
        icon: mdi:calendar-sync-outline
        state: >
          {%- set seconds = (now() - states.sensor.weather_station_weewx_update_datetime.last_changed).total_seconds() -%}
          {{ seconds < 120 }}
        availability: >
          {{ has_value('sensor.weather_station_weewx_update_datetime') }}
        device_class: connectivity

  #############################################################################

homeassistant:
  customize:
    sensor.weather_station_outtemp_c:
      friendly_name: "Ventus W830 Temperatur"
    sensor.weather_station_intemp_c:
      friendly_name: "Ventus W830 Temperatur (innen)"
    sensor.weather_station_dewpoint_c:
      friendly_name: "Ventus W830 Taupunkt"
    sensor.weather_station_indewpoint_c:
      friendly_name: "Ventus W830 Taupunkt (innen)"
    sensor.weather_station_windchill_c:
      friendly_name: "Ventus W830 Windkühle"
    sensor.weather_station_apptemp_c:
      friendly_name: "Ventus W830 gefühlte Temperatur"
    sensor.weather_station_heatindex_c:
      friendly_name: "Ventus W830 Hitzeindex"
    sensor.weather_station_humidex_c:
      friendly_name: "Ventus W830 Luftfeuchte-Index"
    sensor.weather_station_outhumidity:
      friendly_name: "Ventus W830 Luftfeuchte"
    sensor.weather_station_inhumidity:
      friendly_name: "Ventus W830 Luftfeuchte (innen)"
    sensor.weather_station_altimeter_mbar:
      friendly_name: "Ventus W830 Luftdruck (Altimeter, QNH)"
    sensor.weather_station_pressure_mbar:
      friendly_name: "Ventus W830 Luftdruck (Absolut, QFE)"
    sensor.weather_station_barometer_mbar:
      friendly_name: "Ventus W830 Luftdruck (Meeresspiegel, Temperatur, QFF)"
    sensor.weather_station_windspeed_kph:
      friendly_name: "Ventus W830 Windgeschwindigkeit"
    sensor.weather_station_windgust_kph:
      friendly_name: "Ventus W830 Böengeschwindigkeit"
    sensor.weather_station_winddir:
      friendly_name: "Ventus W830 Windrichtung"
    sensor.weather_station_windgustdir:
      friendly_name: "Ventus W830 Böenrichtung"
    sensor.weather_station_windrun_km:
      friendly_name: "Ventus W830 Windlauf"
    sensor.weather_station_rainrate_mm_per_hour:
      friendly_name: "Ventus W830 Regenrate"
    sensor.weather_station_rain_mm:
      friendly_name: "Ventus W830 Regen"
    sensor.weather_station_rain24_mm:
      friendly_name: "Ventus W830 Regen (24h)"
    sensor.weather_station_hourrain_mm:
      friendly_name: "Ventus W830 Regen (Stunde)"
    sensor.weather_station_dayrain_mm:
      friendly_name: "Ventus W830 Regen (Tag)"
    sensor.weather_station_evapotranspiration_mm:
      friendly_name: "Ventus W830 EvapoTranspiration (ET)"
    sensor.weather_station_radiation_wpm2:
      friendly_name: "Ventus W830 Sonnenstrahlung"
    sensor.weather_station_maxsolarrad_wpm2:
      friendly_name: "Ventus W830 Sonnenstrahlung Maximum"
    sensor.weather_station_cloudbase_meter:
      friendly_name: "Ventus W830 Wolkenuntergrenze"
    sensor.weather_station_uv:
      friendly_name: "Ventus W830 UV-Index"
    sensor.weather_station_weewx_update_datetime:
      friendly_name: "Ventus W830 Letzte Aktualisierung"
    binary_sensor.weather_station_weewx_connected:
      friendly_name: "Ventus W830 Regelmäßige Aktualisierungen"
1 Like

Hello all
I am trying to bring this example into the MQTT format for version 2022.12.0.
Unfortunately I have absolutely no idea how and all attempts to bring the upper into a mqtt.yaml fail.

I hope you can help me with this as I don’t really understand the new format.

Many thanks in advance
Guido

Hey, was confused as you are talking about changes in 2022.12. I believe these changes came some releases ago BUT the old format was deprecated with 2022.12.

Anyhow, it’s not that complicated of a change. I’ve just updated my post above with the working weewx.yaml configuration. Hope it works for you as well!

Hello ThomDietrich

Thanks for the change

I was able to save the file mqtt.yaml successfully with your information.
However, I still get an error message.
I have this entry in configuration.yaml:

mqtt: !include mqtt.yaml

and I get the following error message:

Invalid config for [mqtt]: [mqtt] is an invalid option for [mqtt]. Check: mqtt->mqtt->mqtt. (See /config/configuration.yaml, line 10)

Do I have to make another entry in configuration.yaml?

You need to learn about packages. I always felt that the concept and a base configuration should be part of the default configuration! Anyhow, please read here: Packages - Home Assistant

  1. In your configuration.yaml add:
    homeassistant:
      packages: !include_dir_named packages
    
  2. Create the folder packages
  3. Create and fill packages/weewx.yaml with the content above.

In parallel you can create all kinds of yaml files, for topics. Here is a random example I found via google: home-assistant-config/packages at master · aneisch/home-assistant-config · GitHub

Thank you for your help with my problem.
Everything is now working as it should.

I wish you all a merry and healthy christmas.
Guido

Hello,

Is it possible to send the MQTT section of your weewx.conf file ?
I have problems with reading the values ?

Grtz

hi, this is the section in the weewx.conf

[[MQTT]]
    server_url = mqtt://username:[email protected]:1883
    topic = weather
    unit_system = METRIC
    retain = True

username & password have to be defined in the config of the mosquitto broker @homeassistant in the config tab. hope it helps.

greez

Have Problems to receive data of my weewx station.

i installed the addon in weewx and add this to my config:

    [[MQTT]]
        server_url = mqtt://mqtt_user:[email protected]:1883
        topic = weather
        unit_system = METRIC

i also added this to my configuration.yaml in HA.

#-------------------------------------------------------------
# Weatherstation WEEWX-MQTT
#-------------------------------------------------------------
mqtt:
  sensor:
    - state_topic: "weather/outTemp_C"
      name: "Outdoor Temperature"
      unit_of_measurement: "C"
      device_class: "temperature"
      value_template: "{{ value | round(1) }}"
      icon: "mdi:thermometer"
    - state_topic: "weather/windSpeed_kmh"
      name: "Wind Speed"
      unit_of_measurement: "kmh"
      value_template: "{{ value | round(1) }}"
      icon: "mdi:weather-windy-variant"
    - state_topic: "weather/windGust_kmh"
      name: "Wind Gust"
      unit_of_measurement: "kmh"
      value_template: "{{ value | round(1) }}"
      icon: "mdi:weather-windy"

in the LOG of the Mosquitto Broker i see only

...
023-08-18 07:25:43: New connection from 192.168.1.215:36185 on port 1883.
2023-08-18 07:25:43: New client connected from 192.168.1.215:36185 as weewx_e7f53078 (p2, c1, k60, u'mqtt_user').
2023-08-18 07:26:45: New connection from 172.30.32.2:54454 on port 1883
....

Log in weewx looks ok…

....
Aug 18 08:36:42 raspberrypi weewx[874] INFO user.mqtt: data will be uploaded to mqtt://mqtt_user:[email protected]:1883
...
...
Aug 18 08:40:37 raspberrypi weewx[874] INFO user.mqtt: client established for mqtt://mqtt_user:[email protected]:1883
Aug 18 08:40:37 raspberrypi weewx[874] INFO weewx.restx: MQTT: Published record 2023-08-18 08:40:00 CEST (1692340800)
...

@noxx - try

    - name: My Temperature
      state_topic: "weather/loop"
      unit_of_measurement: '°C'
      value_template: '{{ value_json.outTemp_C | round(1) }}'

Hello @noxx,

First thing that immediately catches my eye: in MQTT Explorer we can see windSpeed_kph but you are trying to subscribe to windSpeed_kmh in HA. Please check your definitions.