Unable to create REST sensor from strange json

Hi all,

I have a wifi thermostat that can be controlled by sending restful commands, which is working fine.
However I’m having trouble creating a REST sensor from the received json.
Ideally I would like to have all objects under “data” but for the test I only use “current_temp”

rest:
  - resource: http://192.168.0.131:60004/gateway/device/state?gid=E8DB84CFB8CC&dev_id=1&dev_type=1
    scan_interval: 60
    sensor:
      - name: "Ac1"
        value_template:  "{{ value_json['data']['current_temp'] }}"

and the resulting json:

{
  "date": "2024-01-13 20:23:32",
  "status": 0,
  "message": "SUCCESS",
  "data": "{\"work_mode\":2,\"wind_mode\":4,\"set_temp\":35,\"current_temp\":17}"
}

I tried numerous different ways but nothing works to get the results contained under “data” object.
Can anyone help with the correct template?
Thanks in advance!
Svet

Try this version:

rest:
  - resource: http://192.168.0.131:60004/gateway/device/state?gid=E8DB84CFB8CC&dev_id=1&dev_type=1
    scan_interval: 60
    sensor:
      - name: "Ac1"
        value_template:  "{{ (value_json['data'] | from_json).current_temp }}"

EDIT

Correction. Removed extraneous initial line.

1 Like

Wow, amazing! Works like a charm!
I could never figured it our alone…
Thanks so much, Taras !!!

1 Like