RESTsensor POST JSON unknown Problem

Hello community,
I know there are many topics regarding JSON, RESTsensor and its whole parsing stuff. I have read many of them and I think my configuration is correct, but Home Assistant is still showing “unknown” as value. Can you give me a hint? :slightly_smiling_face:

The JSON response inside the body of my POST response:

{
  "devices": [
    {
      "deviceid": "xxx",
      "lastseen": 1617546078,
      "lowbattery": false,
      "measurement": {
        "idx": 44341,
        "ts": 1617546077,
        "c": 1617546078,
        "lb": false,
        "t1": 17.9,
        "t2": 10.2
      }
    }
  ],
  "success": true
}

And my configuration.yaml

  - platform: rest
    method: POST
    resource: https://www.data199.com/api/pv1/device/lastmeasurement?deviceids=xxx
#    value_template: '{{value_json.devices[0].measurement.t1}}'
#    value_template: '{{ value_json["devices"][0]["measurement"]["t1"] }}'
    name: "Teich Versuch 3"
    unit_of_measurement: "Try"
    scan_interval: 60

I have tried both commented lines, I have tried the parameter ?deviceids via payload instead of resource… the entity is always “unknown”. I wanted to try less nested values of the JSON like “lastseen” but also just “unknown”…

I finally fixed this issue and wanted to share the solution with you (use your own device ID / phone ID for mobile-alerts of course).

First I optimized the REST Sensor but it never worked. Altough the configuration matches my POSTMAN config and everything is alright from my perspective, the sensor is always “unknown”.

  - platform: rest
    resource: https://www.data199.com/api/pv1/device/lastmeasurement
    method: POST
    headers:
      Content-Type: application/x-www-form-urlencoded
    payload: '{ "deviceids" : "XXX", "phoneid" : "XXX" }'
    value_template: '{{ value_json["devices"][0]["measurement"]["t1"] }}'
    name: "Teich Versuch Rest"
    unit_of_measurement: "Try"
    scan_interval: 60

So I switched to a command line sensor and after a few formatting changes I ended up with this one:

  - platform: command_line
    name: "Teich Versuch CURL"
    command: "curl --location --request POST 'https://www.data199.com/api/pv1/device/lastmeasurement' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'deviceids=XXX' --data-urlencode 'phoneid=XXX'"
    value_template: '{{ value_json["devices"][0]["measurement"]["t1"] }}'
    unit_of_measurement: "°C"
    scan_interval: 60

The curl sensor is now working fine! I still don´t know why the REST sensor is not working, so if you have any idea please feel free to comment.

Best regards :slight_smile: