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 support for the MQTT integration's expire_after setting #200

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

airdrummingfool
Copy link

First off, thanks for this great project! I have been using it for months to get usage from my gas and water meters into HA.

Recently I discovered that I was missing a couple weeks of data for my sensors - rtlamr2mqtt had stopped collecting and sending sensor information to MQTT. It apparently didn't lose its MQTT connection, because it didn't publish the LWT message. I didn't see any obvious issues and a restart solved it, so I focused on finding a way to alert and recover from this if it happened again.

It turns out, Home Assistant's MQTT integration has a setting called expire_after which is exactly what I am looking for:

If set, it defines the number of seconds after the sensor’s state expires, if it’s not updated. After expiry, the sensor’s state becomes unavailable. Default the sensors state never expires.

This PR doesn't change the default behavior, but if expire_after is provided for a meter, it will pass that option into the MQTT discovery payload, which HA will use to cause the sensor to become unavailable after expire_after seconds have passed without a sensor reading. This should thus be set to something larger than the expected period between sensor readings (e.g. larger than sleep_for).

Thanks again!

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.

1 participant