core icon indicating copy to clipboard operation
core copied to clipboard

MQTT Binary Sensor Unavailable

Open fishcharlie opened this issue 3 years ago • 11 comments

The problem

I have a MQTT Binary Sensor setup with Home Assistant along with the Mosquitto broker add on.

However, it seems to be stuck at Unavailable, even after sending a bunch of messages that should trigger the state.

Screen Shot 2022-02-19 at 7 41 17 PM Screen Shot 2022-02-19 at 7 42 08 PM

What version of Home Assistant Core has the issue?

core-2022.2.9

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

MQTT Binary Sensor

Link to integration documentation on our website

https://www.home-assistant.io/integrations/binary_sensor.mqtt/

Diagnostics information

No response

Example YAML snippet

binary_sensor:
  - platform: mqtt
    name: "Laundry Room Power"
    state_topic: "home-assistant/laundryroom/power/state"
    payload_on: "on" # Power
    payload_off: "off" # No Power
    availability:
      - topic: "home-assistant/laundryroom/power/availability"
        payload_available: "online"
        payload_not_available: "offline"
    qos: 1
    device_class: power
    value_template: "{{ value_json.state }}"
    expire_after: 120
    off_delay: 300

Anything in the logs that might be useful for us?

No response

Additional information

No response

fishcharlie avatar Feb 20 '22 02:02 fishcharlie

mqtt documentation mqtt source (message by IssueLinks)

Hey there @emontnemery, mind taking a look at this issue as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

I have the same issue, my mqtt sensors stays unavailable even if the logs shows that the online message have been received. Same thing for mqtt switches.

miljbee avatar Mar 22 '22 12:03 miljbee

I have a similar issue. If my home assistant crashes, home assistant doesn't acknowledge the alive message of the sensor when it returns, I have to restart the application to get status back.

Lavaerius avatar Mar 28 '22 21:03 Lavaerius

Please share diagnostic data for the MQTT config entry to aid debugging this issue 👍

emontnemery avatar Apr 07 '22 08:04 emontnemery

It's self discovery mqtt device. Payload = "{"name":"garageSonar","device":"{"identifiers": ["garageSonar"],"name": "garageSonar"}, "device_class":"motion","off_delay":"1", "state_topic":"garageSonar/state","unique_id":"garageSonar","value_template":"{{ value_json.STATE }}"}"

home_assistant_payload="{"STATE":"ON", "unique_id":"garageSonar","device":"{"identifiers": ["garageSonar"],"name": "garageSonar"}}"

I might have fixed it recently by adding in a retain of true into the payloads. after that, it seems to respect the state messages when HA is restart.

Lavaerius avatar Apr 07 '22 12:04 Lavaerius

I have this problem here. I am using the sensor for an SSD, to see if that's connected to the Pi or not, and it's more logical to say that it's "available" or "unavailable" then to say that it's "on" or "off". I'm sending the MQTT from Node-RED (on the same Pi with regular Raspbian and core install of Hass), and I have set retain to true in that.

But this seems to be a long running problem, I have seen two year old comments on this. I don't know if it has ever worked as it should.

Mastiffen avatar Jun 13 '22 13:06 Mastiffen

As a follow up, I actually found my issue.

I was setting the retention flag to MQTT in the status message, but not in the origination message. I finally found something to piece this problem together for me finding this example https://www.home-assistant.io/docs/mqtt/discovery/#motion-detection-binary-sensor I'm running the sensor in python, the pertitent line of code for me was: client.publish(topic,Payload,retain=True) in my register_sensor function

Lavaerius avatar Jun 13 '22 13:06 Lavaerius

@Lavaerius I just managed to fix it myself! Weird thing, I had to add qos : 0 to get it working. Or maybe the stars just aligned after 20-30 restarts and attempts... 🤣

Mastiffen avatar Jun 13 '22 14:06 Mastiffen

same problem here. Tested qos and retain setting with no luck

  • platform: mqtt
    state_topic: "sprinkler/cmd" command_topic: "sprinkler/cmd" name: sprinkler unique_id: sprinkler payload_on: "start" payload_off: "stop"

rhoddan avatar Jun 21 '22 21:06 rhoddan

any updates on this? still getting this issue

ljmerza avatar Sep 21 '22 00:09 ljmerza

Same issue for me. I just updated to 2022.11.1 and my MQTT sensors are showing as "Unavailable" but I can see all of the MQTT messages in the MQTT "listen" test.

brianmiller avatar Nov 08 '22 19:11 brianmiller

I have the same Issue and the sensors are telling me that they are not used anymore from the mqtt integration! This is pretty useless now. I tried the same with qos: 0. The integration test on the sensor topics works and is delivering the values. So the problem is not the broker only the configuration of the sensors.

But i still dont know how to fix it.

Please solve this issue because i need this for my heat control. And it is very cold outside!!

mkornmue avatar Nov 19 '22 15:11 mkornmue

I have the same Issue and the sensors are telling me that they are not used anymore from the mqtt integration! This is pretty useless now. I tried the same with qos: 0. The integration test on the sensor topics works and is delivering the values. So the problem is not the broker only the configuration of the sensors.

But i still dont know how to fix it.

Please solve this issue because i need this for my heat control. And it is very cold outside!!

@mkornmue Did you find a fix? I am having the same issue.

dro159 avatar Nov 28 '22 19:11 dro159

I also really really need this fixed

rhoddan avatar Nov 28 '22 21:11 rhoddan

@dro159 I did find a fix for that. THe main issue was that this configuration is not working when you put it into sub configs. e.g. sensors/mqttsensors.yaml

It is only working in the main configuration file.

mqtt: sensor: - name: "mqttespheatwatertempin" state_topic: "espheat/water/temperature/in" unique_id: "mqttespheatwatertempin" unit_of_measurement: "°C" force_update: true qos: 0 - name: "mqttespheatwatertempoven" state_topic: "espheat/water/temperature/oven" unique_id: "mqttespheatwatertempoven" unit_of_measurement: "°C" force_update: true qos: 0

mkornmue avatar Nov 29 '22 06:11 mkornmue

not working with value_template

IlyaG9 avatar Jan 08 '23 20:01 IlyaG9

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.