import weewx data from mqtt to home assistant.

987 views
Skip to first unread message

Claudio

unread,
Feb 9, 2024, 11:19:31 AM2/9/24
to weewx-user
import weewx data from mqtt to home assistant.
I can't configure the configuration.yaml file, if I go to the mqtt component the weewx topic is visible but it doesn't create the entities for me and when it creates them it tells me that they are not active.
Does anyone have an example of the configuration.yaml for me

Thank you
Claudio

Vetti52

unread,
Feb 9, 2024, 5:31:28 PM2/9/24
to weewx-user
It is easier to keep the mqtt data in a separate file.
So just add in your configuration.yaml the line

mqtt: !include mqtt.yaml

and create a separate mqtt.yaml file containing the data, you have exported from weewx into your mqtt broker.
My mqtt.yaml looks like (be careful with the indentations!):

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) }}"
    unit_of_measurement: "°C"
  - name: weather_station_intemp_c
    unique_id: uniqueid__weather_intemp_c
    icon: mdi:thermometer
    state_topic: "weather/inTemp_C"
    value_template: "{{ value | round(1) }}"
    unit_of_measurement: "°C"
  - name: weather_station_extratemp1_c
    unique_id: uniqueid__weather_extratemp1_c
    icon: mdi:thermometer
    state_topic: "weather/extraTemp1_C"
    value_template: "{{ value | round(1) }}"
    unit_of_measurement: "°C"

This is just the top of the file. There are a lot more of state/topics, and they must meet those, which you have uploaded to the mqtt broker.
HTH
Peter

Claudio

unread,
Feb 10, 2024, 1:40:42 AM2/10/24
to weewx-user
tanks Peter,
i add in  configuration.yaml the line
mqtt: !include mqtt.yaml
i create in /packages file mqtt.yaml 


but a have this error
Configuration errors
Error loading /config/configuration.yaml: in "/config/configuration.yaml", line 31, column 7: Unable to read file /config/mqtt.yaml.

this is my configuration.yaml file
----------------

# Loads default set of integrations. Do not remove.
default_config:

# Example configuration.yaml entry


# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem
 
homeassistant:
  packages: !include_dir_named packages
 
  # Example configuration.yaml entry
evohome:
  username: "xxxxxxxxxxx"
  password: "xxxxxxxxxxx"
 
# Example configuration.yaml entry


mqtt: !include mqtt.yaml
-------

where am I wrong?

Claudio

unread,
Feb 10, 2024, 2:06:26 AM2/10/24
to weewx-user
if I change:
configuration.yaml

#mqtt: !include mqtt.yaml

and mqtt.yaml
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) }}"
      unit_of_measurement: "°C"
     
    - name: weather_station_intemp_c
      unique_id: uniqueid__weather_intemp_c
      icon: mdi:thermometer
      state_topic: "weather/inTemp_C"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "°C"

    - name: weather_station_extratemp1_c
      unique_id: uniqueid__weather_extratemp1_c
      icon: mdi:thermometer
      state_topic: "weather/extraTemp1_C"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "°C"

no errors
MQTT integration create 3 entities
but value is "Unknown"

Vetti52

unread,
Feb 10, 2024, 5:15:17 AM2/10/24
to weewx-user
Well, as I am not a specialist, I can just forward my working configuration, adopted from 

Another question is, if MQTT needs to allow anonymous access. In my setup I had to allow it by creating 
/etc/mosquitto/conf.d/anon.conf
(or any other file.conf name) with the content

listener 1883
allow_anonymous true

and restart mosquitto.

Claudio

unread,
Feb 10, 2024, 5:22:31 AM2/10/24
to weewx-user
this is mine

persistence false


# mqtt

listener 1883

protocol mqtt


# websockets

listener 9001

protocol websockets


allow_anonymous true

password_file /etc/mosquitto/passwd


acl_file /etc/mosquitto/acl

Screenshot 2024-02-10 alle 08.21.14.png

Before writing here, I also followed the instructions in this post but without success

Vetti52

unread,
Feb 10, 2024, 6:00:14 AM2/10/24
to weewx-user
Ok, so at least weewx is uploading data to mqtt sucessfully.
The only thing, I am concerned from your listing, is the proper formation. But perhaps this is due to your pasting mqtt.yaml in this forum. You have hopefully placed the spaces properly, thus
sensor:               top left
  - name             two spaces indented (starts below the „n“ of sensor)
    unique_id and all following entries for this entity four spaces indented (starts below „name“)

Otherwise I would consider reconfiguring mqtt in home assistant.

HTH
Peter

Claudio

unread,
Feb 10, 2024, 6:05:10 AM2/10/24
to weewx-user
Thanks Peter for your support, I will try and reinstall mosquitto to see if I missed something along the way....
what seems strange to me is that, as you can see from the photo, home assistant is able to read the topic
Claudio

p q

unread,
Feb 10, 2024, 9:14:32 AM2/10/24
to weewx...@googlegroups.com
Yaml files are really picky about formatting. You might try a checking site like yamlint.com

--
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/161d7523-daf6-43c5-b239-507715a6256en%40googlegroups.com.

Claudio

unread,
Feb 10, 2024, 10:52:50 AM2/10/24
to weewx-user
thanks for the tip, it says "Valid YAML!"

Neville Davis

unread,
Feb 10, 2024, 4:27:07 PM2/10/24
to weewx-user
Hi

On my Pi4 I have data from weewx and data from my solar and power/water consumption monitoring system combined to a single MQTT stream and this is used within HAAS.

I also had some issues but I have included here my relevant part of my config yaml.....Note the MQTT section hope this helps...I am running the latest HAAS on my Pi.

Neville

# Actron aircon information
rest:
  - resource: http://192.168.0.51/6.json
    sensor:
      - name: "InsideTemp_AC"
        value_template: "{{ (value_json.roomTemp_oC) }}"
        unit_of_measurement: "°C"
        unique_id: actronTemp
       
      - name: "AirConSetTemp"
        value_template: "{{ (value_json.setPoint) }}"
        unit_of_measurement: "°C"
        unique_id: actronSetTemp

      - name: "AirconRunning"
        value_template: "{{  (value_json.isOn) }}"
        unique_id: actronrunning

      - name: "AirconFanSpeed"
        value_template: "{{  (value_json.fanSpeed) }}"
        unique_id: actronfanspeed

template:
  - sensor:
      - name: "Grid Supplied power calculated"
        device_class: power
        unit_of_measurement: "W"
        state: >
          {% set grid_production = states('sensor.metern_solar') | float(0) %}
          {% set grid_consumption = states('sensor.metern_power') | float(0) %}
            {% if (grid_consumption - grid_production) < 0 %}
              0
            {% else %}
              {{ (grid_consumption - grid_production) }}
            {% endif %}
        unique_id: Grid_supplied
       
  - sensor:
      - name: "To Grid power calculated"
        device_class: power
        unit_of_measurement: "W"
        state: >
          {% set to_grid_production = states('sensor.metern_solar') | float(0) %}
          {% set to_grid_consumption = states('sensor.metern_power') | float(0) %}
            {% if (to_grid_production - to_grid_consumption) < 0 %}
              0
            {% else %}
              {{( to_grid_production - to_grid_consumption) }}
            {% endif %}
        unique_id: Energy_calculated_returned_to_grid
       

## These samples from meterN solar and power as well as  weewx weather system

mqtt:
   sensor:
   - name: "meterN power"
     state_topic: "weather/loop"
     device_class: power
     state_class: measurement
     unit_of_measurement: "W"
     value_template: "{{ (value_json.mNpowerW) }}"
     unique_id: meterN_data_power

   - name: "meterN solar"
     state_topic: "weather/loop"
     device_class: power
     state_class: measurement
     unit_of_measurement: "W"
     value_template: "{{ (value_json.mNsolarW) }}"
     unique_id: meterN_data_solar
     
   - name: "meterN Water usage"
     state_topic: "weather/loop"
     device_class: water
     state_class: total_increasing
     unit_of_measurement: "L"
     value_template: "{{ (value_json.water5min) }}"
     unique_id: MeterN_data_water
     
   - name: "Outside Temperature"
     state_topic: "weather/loop"
     unit_of_measurement: "°C"
     value_template: "{{ (value_json.outTemp_C | round(1)) }}"
     unique_id: Outside temperature deg C
     
   - name: "Outside Humidity"
     state_topic: "weather/loop"
     unit_of_measurement: "%"
     value_template: "{{ (value_json.outHumidity | round(1)) }}"
     unique_id: Outside Humidity percentage
     
   - name: "Air pressure"
     state_topic: "weather/loop"
     unit_of_measurement: "hPa"
     value_template: "{{ (value_json.pressure_mbar | round(2)) }}"
     unique_id: Atmospheric air pressure
     
   - name: "Lounge Temperature"
     state_topic: "weather/loop"
     unit_of_measurement: "°C"
     value_template: "{{ (value_json.inTemp_C | round(1)) }}"
     unique_id: Lounge Temp
     
   - name: "Outside room Temperature"
     state_topic: "weather/loop"
     unit_of_measurement: "°C"
     value_template: "{{ (value_json.extraTemp1_C | round(1)) }}"
     unique_id: Sunroom Temp
     
#   - name: "Dining room Teperature"
#     state_topic: "weather/loop"
#     unit_of_measurement: "C"
#     value_template: "{{ (value_json.acroomtempsensor_C | round(2)) }}"
#     unique_id: Dining Room Temp
     
   - name: "FARS speed"
     state_topic: "weather/loop"
     unit_of_measurement: "rpm"
     value_template: "{{ (value_json.farsSpeed | round(2)) }}"
     unique_id: FARS fan measured speed
     

Neville Davis

unread,
Feb 10, 2024, 4:32:25 PM2/10/24
to weewx-user
Hi

In addition in settings search MQTT and I get

Neville


Name
Entity ID
Integration
Area
Status
Air pressure
sensor.air_pressure
MQTT
Dining room Teperature
sensor.dining_room_teperature
MQTT
FARS speed
sensor.fars_speed
MQTT
Lounge Temperature
sensor.lounge_temperature
MQTT
meterN power
sensor.metern_power
MQTT
meterN solar
sensor.metern_solar
MQTT
meterN Water usage
sensor.metern_water_usage
MQTT
Outside Humidity
sensor.outside_humidity
MQTT
Outside room Temperature
sensor.outside_room_temperature
MQTT
Outside Temperature
sensor.outside_temperature
MQTT

Neville Davis

unread,
Feb 10, 2024, 4:58:34 PM2/10/24
to weewx-user
Hi Note State Topic in all items is “weather/loop” Note this is json data you need to look for the required data in that stream.

Just read more closely

Neville

Claudio

unread,
Feb 18, 2024, 11:09:39 AM2/18/24
to weewx-user

problem weewx sent values ​​with too many decimals. e.g. outTemp_c 12.123456789123456
and Home Assistant couldn't read them
solution:
edit the Mqtt section in the weewx.conf file

[[[[outTemp]]]]

                    units = degree_C             # use F instead of C

                    format = %.2f                # use two decimal places of precision


in this way the value sent has only two decimals

thank you all

Claudio


Reply all
Reply to author
Forward
0 new messages