Help configuring a RESTful sensor for SmartThings Tracker

Hi, I’m trying to extract the presence status for the locations “Home” and “School” from this JSON output. I have validated the output and my HA instance seems to be able to pull the data just fine, but I can’t figure out how to turn it into a sensor. I don’t know JSON (or any programming actually) so I’m struggling with the json_attributes_path, json_attributes, and value_template. What should I set those to? Thanks in advance!

{
  "main": {
    "st": {
      "value": null
    },
    "mndt": {
      "value": null
    },
    "mnfv": {
      "value": "V110AUCU1ASD1"
    },
    "mnhw": {
      "value": "1.0"
    },
    "data": {
      "value": "{\"payload\":{\"if\":[\"oic.if.baseline\"],\"n\":\"x.geofence.list\",\"rt\":[\"x.com.samsung.geofence.list\"],\"x.com.samsung.geofenceList\":[{\"x.com.samsung.regionRadius\":213,\"x.com.samsung.name\":\"Home\",\"x.com.samsung.checkout\":true,\"x.com.samsung.color\":\"#0FC5FC\",\"x.com.samsung.requestTime\":\"1590606021064\",\"x.com.samsung.longitude\":-90.000000000000,\"x.com.samsung.creationTime\":\"1590606021000\",\"x.com.samsung.checkin\":true,\"x.com.samsung.opType\":\"NEW\",\"x.com.samsung.latitude\":45.0000000000000,\"x.com.samsung.id\":73595}]}}"
    },
    "di": {
      "value": "xxxxxxxx"
    },
    "mnsl": {
      "value": null
    },
    "dmv": {
      "value": "IoTivity1.2.1"
    },
    "n": {
      "value": "SmartThings Tracker (0CTR)"
    },
    "mnmo": {
      "value": "SM-V110A_NA_ATT"
    },
    "vid": {
      "value": "IM-TRACKER-NORMAL-000001"
    },
    "mnmn": {
      "value": "Samsung Electronics"
    },
    "mnml": {
      "value": null
    },
    "geofencesStatus": {
      "value": "[{\"id\":83631,\"name\":\"Home\",\"presence\":\"present\"},{\"id\":83633,\"name\":\"School\",\"presence\":\"not present\"}]"
    },
    "mnpv": {
      "value": "2.4"
    },
    "mnos": {
      "value": "Tizen"
    },
    "geofences": {
      "value": "[{\"id\":83631,\"presence\":\"present\"},{\"id\":83633,\"presence\":\"not present\"}]"
    },
    "pi": {
      "value": "xxxxxxxxxxxxx"
    },
    "icv": {
      "value": "core.1.1.0"
    }
  }
}

Welcome…

This might be challenging if you are coming from zero JSON experience, but folks in this community are pretty amazing. Here is an example of one of my rest sensors. Perhaps, this will give you some ideas to get started. If you try something and then post the configuration back in here, it is helpful for people to suggest improvements.

  - platform: rest
    name: tn_info
    resource: http://192.168.80.16/api/v2.0/system/info
    headers:
      Authorization: !secret TrueNAS_API
      Content-Type: application/json
      User-Agent: Home Assistant
    scan_interval: 3600
    value_template: '{{ value_json.uptime }}'
    json_attributes:
      - uptime_seconds
      - version
      - model
      - cores
1 Like

Progress! I added this line:

    value_template: "{{ value_json['main'][0]['geofencesStatus'] }}"

and now I see this in the sensor’s state attributes (whereas before it was blank):

geofencesStatus:
  value: >-
    [{"id":83631,"name":"Home","presence":"not
    present"},{"id":83633,"name":"School","presence":"not present"}]
friendly_name: smartthings_tracker

So now the only thing left to do is parse this out into two separate entities, “Home” and “School”, each of which can be either present or not present.

Now that I have this string as a sensor status, how can I extract it as a template sensor? Some sort of regular expression? I’m afraid I’m way out of my depth here.

Great progress! Okay, now you create the separate entities using a sensor with template where you extract the information that you have above into the newly created sensor. Example below using a similar json approach like yours. You’ll want to study this documentation for the syntax. Note that you can use the Template editor to “practice” your syntax.

- platform: template                                                                                                         
    sensors:                                                                                                                   
      sabnzbd_external_status:                                                                                                 
        friendly_name: "Status"                                                                                                
        icon_template: mdi:cloud-download                                                                                     
        value_template: '{{ states.sensor.sabnzbd_external.attributes["queue"]["status"] }}' 

Note that this would go under a “sensor” block in what is probably your configuration.yaml file.

How did you make the api call to smartthings? I’m hitting https://api.smartthings.com/v1/devices/myIdHere/status and i’m not getting longitude or latitude data…

I eventually gave up on Smartthings altogether. It didn’t help that they killed off the tracker too! All Smartthings Trackers stop functioning at the end of October.

They only killed the AT&T tracker. I had one of the AT&T and one Verizon one. Did you ever figure out a way to get the long and lat for the tracker?