Rest sensor error (cloudlfare)

Can someone tell my why my restfull sensor give me this error:

restfull sensor configuration:

sensor:
#--------------------------------------------------------------------------------------
# cloudflare
#--------------------------------------------------------------------------------------
  - platform: rest
    resource: http://MYIP:8123/api/hassio/addons/9074a9fa_cloudflared/info
    name: cloudflare
    value_template: "{{ value_json.data.state }}"
    scan_interval: 
      minutes: 5
    headers:
      Authorization: 'Bearer  MYTOKEN'
      Content-Type: application/json

the error is:

Logger: homeassistant.helpers.template
Source: helpers/template.py:735
First occurred: 11:27:07 (3 occurrences)
Last logged: 11:29:07

Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.data.state }}’

What is the response from that URL? Please paste as correctly-formatted code.

If you can’t work out how to get it, start with modifying the above to use:

    value_template: "{{ value[:240] }}"

which will show us the first 240 characters of the response, if the REST call is working.

Hello @Troon ,

I did the modification but I have no log out, so seems the rest call is not working… right?

If you reloaded REST sensors and that sensor either doesn’t exist or has no state, correct. Is there anything in the logs? (Settings / System / Logs)

I assume MYTOKEN is your actual token redacted, not just pasted from somewhere else?

The sensor has been created but without states.
Unfortunately I have no logs (just others warning logs from HA).
MYTOKEN is a long life token that I have created just for this rest sensor. I also try to make a new token and test again but no results.

Hey @Troon
may be this can helps?

2023-07-20 15:49:23.804 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.cloudflare, old_state=None, new_state=<state sensor.cloudflare=<!DOCTYPE html><html><head><title>Home Assistant</title><meta charset="utf-8"><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"><link rel="icon" href="/static/icons/favicon.ico"><link rel="modulepreload" href="/fronte; friendly_name=cloudflare @ 2023-07-20T15:49:23.804106+02:00>>

Yes: the response is an HTML document, not a JSON document.

What information are you expecting to get from that URL? Where have you got the information on setting up this sensor?

The scope is to know if an addon (in this case cloudflare) is running.
Sometimes after a blackout , the addon is not able to restart correctly (the tunnel is already in use and the addon is not able to create the connection), so I would create an automation that restart the addon in this case.

Ok, so what does that URL return in the working and not-working states?

Where did your original value_template line come from?

Actually , I’m not so expert, I followed this example:

How to monitor if addon is started or not?.

But I think I’ll try another way.
I’m testing Uptime Kuma now and probaly I’ll be able to solve with this addon…
Thank you anyway for your support @Troon and have a great we.