Help please rest sensor - avoid errors when the inverter is offline

Hi
can someone help me to avoid such errors in the logs continuously?
It’s complaining about the rest sensor that pulls data from my inverter. When the sun doesn’t shine, the rest sensor can’t pull ofcourse because the inverter goes offline.
I already added the availability line, to check whether the inverter is online, but the errors stays unfortunately.

logs:

2024-10-20 19:00:30.941 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-10-20 19:00:30.941 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data

sensor:

sensor:
- platform: rest
  scan_interval: 60
  resource: !secret solax_local_ip
  payload: !secret solax_local_realtime_payload
  method: POST
  headers: 
    X-Forwarded-For: 5.8.8.8
  name: "solax_rest_local"
  unique_id: solax_rest_local
  json_attributes:
    - SN
    - ver
  value_template: >-
    {% if value_json['SN'] and value_json is defined %}
      Active
    {% else %}
      Unavailable
    {% endif %}
  availability: >-
    {{ is_state('binary_sensor.192_168_2_35','on') }}

Hi ,

How is that sensor created? I hope not from this same rest sensor.

No separate from a helper

The code for that might help.

I sorry I meant by added a new integration (ping) and added the IP address of the inverter here:


that created this sensor:
binary_sensor.192_168_2_35

I would look at that sensor in developer - state and make sure on and off is what it is returning. That can change based on the device class.
Mine, for instance, show home and away…
Open your Home Assistant instance and show your state developer tools.

hm after I changed value_template a bit, it no longer reports those errors:

  value_template: >-
    {% if state_attr('sensor.solax_rest_local', 'SN') is defined %}
      Active
    {% else %}
      Unavailable
    {% endif %}
  availability: >-
    {{ is_state('binary_sensor.192_168_2_35','on') }}

so I guess it had to do something with:
value_json is defined