Issue with binary MQTT sensor (off or unavailable)

i have a binary MQTT sensor that tracks an online/offline status. But i am having the following issue:

When the device sends an “online” MQTT message, the sensor shows as “off”
When the device sends an “offline” MQTT message, the sensor shows as “unavailable”

Here is the yaml code:

binary_sensor:
  - platform: mqtt
    name: frigate server
    availability_topic: "frigate/available"
    state_topic: "frigate/available"

I also tried:

binary_sensor:
  - platform: mqtt
    name: frigate server
    state_topic: "frigate/available"
    availability:
      topic: "frigate/available"
      payload_available: "online"
      payload_not_available: "offline"
    device_class: connectivity

The result is the same, i get “off” when the MQTT message is “online” and get “unavailable” when the MQTT message is “offline”

Any ideas on what is wrong here ? i am running 117.4

No response? I’m having the same issue…

If you receive an offline message on your availability_topic, the sensor will be unavailable.

So don’t define an availability_topic

EDIT: better understand MQTT binary sensors now, so this simplified one works without a template (which was throwing LOTS of errors):

binary_sensor:
  - platform: mqtt
    name: "Frigate NVR"
    icon: hass:cctv
    state_topic: "frigate/available"
    payload_on: "online"
    payload_off: "offline"
    device_class: connectivity

And for the alert:

alert:
  frigate_offline:
    name: Frigate Status Alert
    entity_id: binary_sensor.frigate_nvr
    state: "off"
    repeat: 60
    can_acknowledge: true
    done_message: "Frigate NVR is online ({{states('sensor.time')}})"
    message: "Frigate NVR is offline ({{states('sensor.time')}})"
    notifiers:
      - person
    data:
      data:
        importance: 'high'
1 Like