Rest sensor ignores the availability line in the yaml

Hi
I dont get it, the log is full of the following errors while I have defined an availability in the rest sensor?
what am I missing?

the rest sensor must try to pull data ONLY when the inverter is online. it looks like it’s now ignoring the availability line, so when the binary_sensor is not ON, the inverter is offline, so HA needs to skip the pulling…

2024-07-24 01:00:09.471 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:00:09.471 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:01:09.950 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:01:09.950 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:02:09.917 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:02:09.917 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:03:08.477 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:03:08.477 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:04:09.917 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:04:09.918 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:05:09.949 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:05:09.949 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:06:09.917 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:06:09.917 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:07:09.438 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:07:09.438 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:08:09.917 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:08:09.918 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:09:09.950 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:09:09.951 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:10:08.445 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:10:08.446 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:11:09.949 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:11:09.949 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2024-07-24 01:12:09.981 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.2.35/ failed with All connection attempts failed
2024-07-24 01:12:09.981 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data

the yaml:

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"
  json_attributes:
    - SN
    - ver
    - type
    - Data
    - Information
  value_template: 'Active' 
  availability: >-
    {{ states('binary_sensor.192_168_2_35') == 'on' }}
  timeout: 30

Hi Bowa,

My first thought would be to put that into developer - templates and see if this is true or false, on or off, On or Off, whatever exactly. If that’s not changing from on as per your template it will not change the availability of the sensor.

Open your Home Assistant instance and show your template developer tools.

Aster thst make sure the rest of the things are correct, url, passwords, etc are correct because the error (to me) seems like you are not getting connection to the api, not that availability is messing you up but I cannot tell exactly.

It’s a binary sensor. The states will only be on or off.

I’d use this though:

{{ is_state('binary_sensor.192_168_2_35','on') }}

@tom_l thanks let’s see if that changes anything. I will respond to this tomorrow because the inverter needs to go offline first. But your solution looks the same as mine?

@Sir_Goodenough the sensor works, the only thing is that HA tries to pull data when the inverter is offline (so during nights), and that’s not possible obviously. that’s why I was looking into the availability thing in the sensor.

There is an open (ignored) issue regarding this

2 Likes

My point is test the sensor you have on the IP address is that completely functioning. I would expect if the availability binary sensor were indeed changing to off, it should not be available and should not poll. You have the right idea, just see exactly what the binary sensor is giving you. You are looking fo on, and it seems that is there. Make sure it is flipping when you think it is. I didn’t know about the

issue, so if the availability is changing to none that might be a problem.
I have an availability template as a custom template in one of by blue message footer links you are welcome to use or learn from it it helps. \/ below \/

The errors stays unfortunately.
I guess we need to wait until the github issue has been resolved…

Or use my availavility-template which is OK with none… (Handles it correctly)