mqttsensorshome-assistant

configure binary sensor from mqtt


I have zway controller with MQTT client enabled and binary sensors which publish state to mqtt topic.

zway95/data/ZWayVDev_zway_9-0-48-12

{
  "creationTime": 1587157138,
  "creatorId": 1,
  "customIcons": {},
  "deviceType": "sensorBinary",
  "firmware": "3.80",
  "h": 1979762458,
  "hasHistory": false,
  "id": "ZWayVDev_zway_9-0-48-12",
  "location": 3,
  "locationName": "Коридор",
  "manufacturer": "Shenzhen Neo Electronics Co., Ltd",
  "metrics": {
    "probeTitle": "Motion",
    "scaleTitle": "",
    "icon": "motion",
    "level": "off",
    "title": "Движение - Коридор",
    "isFailed": false
  },
  "nodeId": 9,
  "order": {
    "rooms": 0,
    "elements": 0,
    "dashboard": 0,
    "room": 2
  },
  "permanently_hidden": false,
  "probeType": "motion",
  "product": "",
  "tags": [],
  "technology": "Z-Wave",
  "visibility": true,
  "updateTime": 1643685077
}

zway95/state/ZWayVDev_zway_9-0-48-12

off

or

on

Also I have such config in HA

binary_sensor:
  - platform: mqtt
    state_topic: "zway95/state/ZWayVDev_zway_9-0-48-12"
    name: "testmotion"
    device_class: "motion"
    payload_on: "true"
    payload_off: "false"
    availability_template: "{{ value_json.metrics.isFailed }}"
    availability:
      - topic: "zway95/data/ZWayVDev_zway_9-0-48-12"
    payload_available: false
    payload_not_available: true
    json_attributes_topic: "zway95/data/ZWayVDev_zway_9-0-48-12"

In HA sensor looks like unavailble and attributes are missing

Where did I make a mistake?


Solution

  • The way I understand the home assistant documentation availability_template is intended to be used along with availability_topic. So either go for

    availability_template: "{{ value_json['metrics']['isFailed'] }}"
    availability_topic: "zway95/data/ZWayVDev_zway_9-0-48-12"
    payload_available: false
    payload_not_available: true
    

    or

     availability:
       - topic: "zway95/data/ZWayVDev_zway_9-0-48-12"
         payload_available: false
         payload_not_available: true
         value_template: "{{ value_json['metrics']['isFailed'] }}"