Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Assistant discovery metadata #26

Open
ThomDietrich opened this issue Dec 27, 2021 · 11 comments · May be fixed by #36
Open

Home Assistant discovery metadata #26

ThomDietrich opened this issue Dec 27, 2021 · 11 comments · May be fixed by #36

Comments

@ThomDietrich
Copy link

Would you be willing to accept a PR with changes to enable Home Assistant auto discovery?

Out of coincidence I saw that the fork by @anastas78 already has an implementation for this, I wonder if he/she wants to open a PR!?

See https://github.com/anastas78/weewx-mqtt

Best!

@matthewwall
Copy link
Owner

happy to consider this. perhaps this could be done as a generic discovery, not specific to ha?

for example, the option might be something like this:

discovery = [True | False] # default false
discovery_topic = homeassistant/sensor/weewx # default None

and the docs would include an explanation of what the 'config' looks like for each key. or a reference to the ha discovery spec.

i'm a little anxious about sending a discovery message on every loop/archive. perhaps also have a mechanism to indicate how often the discovery info should be sent.

@anastas78 anastas78 linked a pull request Oct 17, 2022 that will close this issue
@juandelarocha
Copy link

Can you please explain how to enable Home Assistant auto discovery using the new mqtt.py developed? I have tried replacing the mqtt.py located in /usr/bin/weewx... but it doesn't work.

@anastas78
Copy link

Can you please explain how to enable Home Assistant auto discovery using the new mqtt.py developed? I have tried replacing the mqtt.py located in /usr/bin/weewx... but it doesn't work.

The easiest way would be to download the updated branch from my repository
i.e:

wget https://github.com/anastas78/weewx-mqtt/archive/refs/heads/ha-discovery-with-lwt.zip -O /tmp/weewx-mqtt.zip && \
cd /tmp && \
wee_extension --install weewx-mqtt.zip

and add the needed configuration in your weewx.conf

@juandelarocha
Copy link

juandelarocha commented Jan 16, 2023

Can you please explain how to enable Home Assistant auto discovery using the new mqtt.py developed? I have tried replacing the mqtt.py located in /usr/bin/weewx... but it doesn't work.

The easiest way would be to download the updated branch from my repository i.e:

wget https://github.com/anastas78/weewx-mqtt/archive/refs/heads/ha-discovery-with-lwt.zip -O /tmp/weewx-mqtt.zip && \
cd /tmp && \
wee_extension --install weewx-mqtt.zip

and add the needed configuration in your weewx.conf

Thanks for your help and implementation @anastas78. I have correctly downloaded, installed and configured the weewx.conf. I have been able to read out_temp by including the following in the configuration.yaml

mqtt: sensor: - name: weewx_out_temp state_topic: "weather/loop" unit_of_measurement: '°C' value_template: > {% if value_json.outTemp_C %} {{ value_json.outTemp_C | round(1) }} {% endif %}

My question is, what should I expect by autodiscovery if I still need to define the variables in the configuration.yaml? Because if I not declare that, I don't receive anything. Maybe I am missing something?

@anastas78
Copy link

Have you added the HA specific configuration in weewx.conf under the [[MQTT]] label ?

[[MQTT]]
    server_url = xxxx
    topic = weather
....... 
    ha_discovery = True
    ha_device_name = NAME_YOUR_DEVICE
    ha_discovery_topic = homeassistant/sensor/weewx/ 

so weewx-mqtt sends sensor data to "weather" topic and config data to "homeassistant/sensor/weewx/" (default topic if you have not changed your HA mqtt client configuration)

My question is, what should I expect by autodiscovery if I still need to define the variables in the configuration.yaml? Because if I not declare that, I don't receive anything. Maybe I am missing something?

That is the idea - you don't have to define anything in HA. All sensors published by weewx-mqtt should be configured directly by the mqtt client of HA though the "ha_discovery_topic" topic. It should create a new device with the name you configure under "ha_device_name" and a bunch of sensors - your weexw sensors.

@CitizenRacer
Copy link

Thank you @anastas78 for your variant. It works great.

@matthewwall I think this would be a great addition to the Weewx mqtt plugin. It makes Home Assistant integration so much easier!

@timnis
Copy link

timnis commented Jul 29, 2023

Hi, just installed this and it partly works.
Partly I mean I can see part of the sensors in HA (like below)
image

But for example there is no rain_mm sensor. And on HA MQTT error log there is following error

2023-07-28 18:48:56.211 ERROR (MainThread) [homeassistant.components.mqtt.mixins] Error 'expected SensorDeviceClass or one of 'date', 'duration', 'enum', 'timestamp', 'apparent_power', 'aqi', 'atmospheric_pressure', 'battery', 'carbon_monoxide', 'carbon_dioxide', 'current', 'data_rate', 'data_size', 'distance', 'energy', 'energy_storage', 'frequency', 'gas', 'humidity', 'illuminance', 'irradiance', 'moisture', 'monetary', 'nitrogen_dioxide', 'nitrogen_monoxide', 'nitrous_oxide', 'ozone', 'pm1', 'pm10', 'pm25', 'power_factor', 'power', 'precipitation', 'precipitation_intensity', 'pressure', 'reactive_power', 'signal_strength', 'sound_pressure', 'speed', 'sulphur_dioxide', 'temperature', 'volatile_organic_compounds', 'volatile_organic_compounds_parts', 'voltage', 'volume', 'volume_storage', 'water', 'weight', 'wind_speed' for dictionary value @ data['device_class']' when processing MQTT discovery message topic: 'homeassistant/sensor/weewx/rain_mm/config', message: '{'name': 'rain_mm', 'unique_id': 'WMR300_rain_mm', 'device_class': 'mm', 'unit_of_measurement': 'mm', 'state_topic': 'weather/loop', 'value_template': '{{ value_json.rain_mm | float | round(1) }}', 'availability_topic': 'weather/availability', 'device': {'name': 'WMR300', 'manufacturer': 'weewx', 'model': 'WMR300', 'hw_version': 'weewx_version:4.10.2', 'sw_version': 'weewx-mqtt:0.24', 'identifiers': ['WMR300']}, 'platform': 'mqtt'}'

Any ideas how to fix this?

@anastas78
Copy link

Hello @timnis,
Just made some changes to the sensor types to match the evolution in HA sensor types and added the missing mm and mm_per_hour. (Thanks to @dcapslock for his review) Please check it #36

@timnis
Copy link

timnis commented Aug 19, 2023

Hello @anastas78 ,
Thanks for update, now I see the rain 😃

@jshatch
Copy link

jshatch commented Dec 13, 2023

@anastas78 Though this is working for me, I find that having a new discovery message pop in on every loop might be causing issues (for instance I'm seeing the availability flap in openHAB). Can the discovery topic be linked to just report generation?

(edit: I blocked the HA discovery topic on my broker temporarily and sure enough the errors in the logs about going OFFLINE / UNKNOWN / ONLINE stopped. Adding that topic back into the aclfile immediately started the errors again.)

@avfoto
Copy link

avfoto commented Jan 30, 2024

@anastas78 When I run weewx before install your code I get...
" TypeError: MQTTThread.init() got an unexpected keyword argument 'ha_discovery'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants