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

Add LWT to mqtt connection #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ThomDietrich
Copy link

@ThomDietrich ThomDietrich commented Sep 11, 2022

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: "°"

@ThomDietrich
Copy link
Author

ThomDietrich commented Sep 13, 2022

@roe-dl would you mind testing this?

It's pretty straight forward and works as intended in my setup.

@roe-dl
Copy link

roe-dl commented Sep 17, 2022

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.

@ThomDietrich
Copy link
Author

@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.

@roe-dl
Copy link

roe-dl commented Sep 18, 2022

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.

@ThomDietrich
Copy link
Author

ThomDietrich commented Sep 18, 2022

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

@ThomDietrich
Copy link
Author

@matthewwall ready to merge

@ThomDietrich
Copy link
Author

Added one improvement where the broker would eventually decide to mark as offline and the running weewx wouldn't care.

@juandelarocha
Copy link

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?

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 this pull request may close these issues.

Last will and testament missing
3 participants