weewx-mqtt
weewx-mqtt copied to clipboard
Add LWT to mqtt connection
Fixes #21
For testing in Home Assistant:
mqtt:
sensor:
- 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/lwt"
unit_of_measurement: "°"
@roe-dl would you mind testing this?
It's pretty straight forward and works as intended in my setup.
I tested it.
For that I used a simple WeeWX installation including the driver to fetch the weather data from my weather station and the MQTT extension in patch-1 version.
- Topic "lwt" is sent to the broker.
- It becomes "online" when WeeWX is started.
- It immediately becomes "offline" when WeeWX is stopped.
- If I pull the plug of the PC that is running WeeWX (i.e. hard shutdown), the topic "lwt" remains "online" for some time, and then becomes "offline".
- After reboot it becomes "online" again.
So I guess, it works as it should do.
@roe-dl your test is way more detailed than my own. Everything sounds exactly as it should. Amazing, thank you. @matthewwall ready to merge.
the topic "lwt" remains "online" for some time, and then becomes "offline".
Fyi: This is MQTTs lwt feature at its best. When the client disconnects cleanly, "offline" is set by the broker right away. If the client dies off, the broker publishes "offline" after a certain timeout.
One question: Why is the topic called "lwt"? I found it not really intuitive. What about "connection" or "server"? Together with the possible values "offline" and "online" those names would be self explaining, I guess.
It's an established topic name used by many project. However, I agree with you. Alternatives are "availability" or "connection_status". I will go with the first
@matthewwall ready to merge
Added one improvement where the broker would eventually decide to mark as offline and the running weewx wouldn't care.
So just to be clear, even though I have installed the autodiscovery variant of weewx-mqtt, I should declare this LWT in the configuration.yaml because otherwise I cannot "discover" anything. Am I doing right? Or i'm missing something?