Rest sensor fails when inverter is offline

Hi
I’ve got a rest sensor which pulls data from my inverter into HA. but when the inverter is offline it throws this error because it’s unable to retrieve data:

* Error fetching data: http://192.168.1.1/ failed with All connection attempts failed

Is there a way to avoid the rest sensor to retrieve data when it’s offline?

sensor:
- platform: rest
  scan_interval: 300
  resource: !secret solax_local_ip
  payload: !secret solax_local_realtime_payload
  method: POST
  headers: 
    X-Forwarded-For: 5.8.8.8
  json_attributes:
    - Data
  value_template: 'OK'

the scan_interval keeps going despite of the inverter status

you need this key and determine a value for it.
RESTful Sensor - Home Assistant.

What means do you have to see it is offline? Usually it is the rest call failing that determines the offline status.

If you do, then probably setting the scan interval very low, and create an automation to manually update:

- service: homeassistant.update_entity
  entity_id: sensor.your_rest_sensor

What do you mean?

You have to create a template that tells you when it is available, IE has valid data.
There is a custom_template in my tag links that might help, and there are other ways.

I did not know the availability template also prevents polling when unavailable. I thought it was only to influence the default availability state.

Is it a “normal” situation that the inverter is online?
If so, you might:

  • Create a ping sensor on your inverter
  • Use that binary_sensor as the source of the availability template of the rest sensor.

Thanks for the suggestion!
so I created a ping sensor which polls the inverter and added the availability line below the rest sensor.
you mean something like this?

sensor:
- platform: rest
  scan_interval: 300
  resource: !secret solax_local_ip
  payload: !secret solax_local_realtime_payload
  method: POST
  headers: 
    X-Forwarded-For: 5.8.8.8
  json_attributes:
    - Data
  value_template: 'OK'
  availability: "{{ states('binary_sensor.192_168_1_1') == 'on' }}"

so the binary sensor (inverter) needs to be ON before the rest sensor begins to work, right?

Looks good, although it seems unlikely your inverter has “192.168.1.1” as IP, does it?

No it has another ip indeed, was just an example