Grabbing data via mqtt

With the object below, how do I query the battery data using platform mqtt?

{
  "id": "f4f839cd40fd",
  "address": "f4:f8:39:cd:40:fd",
  "rssi": -43,
  "serviceData": {
    "model": "H",
    "modelName": "WoHand",
    "mode": false,
    "state": false,
    "battery": 93
  }
}

I do believe this will not work.

  - platform: mqtt
    name: "Jcom Tv Box Battery"
    state_topic: 'switchbot/bot/f4f839cd40fd/serviceData'
    value_template: '{{ value_json.battery }}'
    unit_of_measurement: "%"
    icon: mdi:battery
    value_template: '{{ value_json.serviceData.battery }}'

For future reference, you can use this tool to determine the appropriate JSON path:

https://jsonpathfinder.com

2 Likes