Mqtt sensor format Home Assistant 2023.10.3

I updated HA last weekend and ended up with lots of broken mqtt devices. Ive been able to fix my mqtt switches, but having issues converting my sensors to the new format. My sensor state is unknown, but I’m receiving mqtt updates for the motion dect. TIA.

- sensor:
      unique_id: Office Motion Sensor
      name: "Office Motion Sensor"
      state_topic: "tele/sonoff/RESULT"
      unit_of_measurement: "dBm"
      value_template: '{{value_json.RfReceived.Data}}'
      payload_available: 'E39E3E'  
      payload_not_available: 'E39E3Eoff'

MQTT message…
Message 0 received on tele/sonoff/RESULT at 9:18 PM:

{
    "Time": "2023-10-18T02:18:32",
    "RfReceived": {
        "Sync": 12540,
        "Low": 420,
        "High": 1220,
        "Data": "E39E3E",
        "RfKey": "None"
    }
}
QoS: 0 - Retain: false

Sucking out JSON attributes is never easy is it…

I’m far from an expert here, however a couple things jump out.

  1. you have a ‘unit_of_measurement’ of dBM. However, if I read this correctly, you are getting a value for ‘.Data’ of “E39E3E”. That does not appear to be a valid dBm value. Do you think HA did something to check if the value received is compatible with selected ‘unit_of_measurement’?

  2. Seems like you are mixing your state_topic with your availability_topic, I’ve always had these separate, or a least explicitly defined each topic, example below.

Good hunting!

  # Third Reality
  - name: "Garage Sliding Door East"
    device_class: door
    unique_id: "0x282c02bfffe7998b-door"
    expire_after: 3600
    state_topic: "zigbee2mqtt/0x282c02bfffe7998b"
    value_template: "{{ value_json.contact }}"
    payload_off: false
    payload_on: true
    availability_topic: zigbee2mqtt/0x282c02bfffe7998b/availability
    json_attributes_topic: "zigbee2mqtt/0x282c02bfffe7998b"

A motion sensor is a binary sensor, not a sensor

- binary_sensor:
    unique_id: Office Motion Sensor
    name: "Office Motion Sensor"
    state_topic: "tele/sonoff/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: 'E39E3E'  
    off_delay: 30

Thx Francis, made the changes, but still had issues. After a few hours, I went a different route. I used node red and 3 minutes later its all working again.

image