MQTT Discovery - Availability

I am trying to add availability to my discovered sensor. The temperature is discovered fine with

Topic:

homeassistant/sensor/inkbird_f8300232744d/temperature1/config

Payload

{
	"name":"inkbird_f8300232744d_temperature1",
	"device_class":"temperature",
	"state_topic":"inkbird_f8300232744d/temperatures",
	"unit_of_measurement":"°C",
	"unique_id":"inkbird_f8300232744d_temperature1",
	"value_template":"{{value_json.temperature1}}"
}

working

If I publish a similar config with availability:

{
	"name":"inkbird_f8300232744d_temperature1",
	"device_class":"temperature",
	"state_topic":"inkbird_f8300232744d/temperatures",
	"availability_topic":"inkbird_f8300232744d/availability",
	"payload_available":"Online",
	"payload_not_available":"Offline",
	"unit_of_measurement":"°C",
	"unique_id":"inkbird_f8300232744d_temperature1",
	"value_template":"{{value_json.temperature1}}"
}

I get this shown for my gauge in lovelace:
non-numeric

Any help will be appreciated!

My guess is you haven’t published Online to inkbird_f8300232744d/availability.

I used your discovery topic and payload to create the sensor. Here’s how it appears in Developer Tools > States:

Its state is unavailable (which is certain to cause “Entity is non-numeric” for the Gauge card).

I then publish {"temperature": 23 } to inkbird_f8300232744d/temperatures. However, the sensor’s reported state remains the same: unavailable

Why? Because it has not yet received information for the availability_topic.

Finally, I publish Online to inkbird_f8300232744d/availability. Now it knows the sensor’s availability status (Online) and its state (23) and displays the following:

In practice, both the temperature and the availability should be published as retained messages. It instructs the broker to store the values. If Home Assistant disconnects from the broker and then reconnects (like after a restart) it will immediately receive the stored values (as opposed to waiting for the next time the physical sensor reports its state and availability).

1 Like

That looks like it. For some reason I can’t get my MQTT library to publish a retained message. I set the flag, but it doesn’t work. :frowning:

I was thinking that availability offline might make the gauge disabled or similar, but I just get the error. Now, I am not sure of the point! :slight_smile:

That will become inconvenient because whenever Home Assistant restarts and re-subscribes to the state_topic it will receive no payload (and the sensor will have no numeric value to report).

You might make the Gauge card part of a Conditional card. The condition would be the the sensor’s state is not unavailable.

1 Like

Thanks again for your help.