Rest sensor error - gets unavailable

I have a restful sensor looking like this

sensor.yaml

- platform: rest
  name: state
  scan_interval: 10
  resource: http://"myurl"
  value_template: '{{ value_json.state }}'

Most of the time the sensors works fine. Sometimes it doesn’t goes unavailable.

I also get errors:

Error fetching data: <PreparedRequest [GET]> from http://“myurl” failed with HTTPConnectionPool(host=‘myip’, port=someport): Max retries exceeded with url: myurl (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x6ab287b0>: Failed to establish a new connection: [Errno 111] Connection refused’,))

bold values changed

try something like this:

{% if value_json is defined and value_json.state is defined %}
  {{ value_json.state }}
{% else %}
  states.sensor.state.state
{% endif %}

That way if the state becomes unavailable then the sensor will keep the last good sensor value. I think…

And if I were you I would change that sensor name to something other than “state”. As you can see using that name starts making obtaining the state of the sensor.state from the states very confusing very quickly. :crazy_face:

Thanks, but so will still get that error right?

It would pleasure my OCD :wink: better if I could get the error away than doing it with a workaround.

probably but some times there’s nothing you can do about that.

if you can fix that then obviously that would be better.

@ycardon I use this sensor to read the values from your gigaset api.

The error says:

Max retries exceeded with url

Is there a max retry value for the reaching the api?