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’,))
{% 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.