WTH can't a sensor retain its state if it goes unavailable

I have configured the following sensor:

sensor:
  - platform: command_line
    name: eskom_loadshedding_status
    command: "curl https://loadshedding.eskom.co.za/LoadShedding/GetStatus"
    value_template: '{{ value | round(0) | abs - 1 }}'

The URL is rather unstable and it flips between returning a value and being unavailable which results in returning of 0. Why can’'t we set an attribute on the sensor so that if the sensor becomes unavailable, it will retain its status until it tries again? I’ve had automatons not run because of the issue with the URL in question.

Most people would like to know if their reliable sensors go offline which is why it is not done. You can do it by including logic for what you want in the template. e.g. {% if value = 'unavailable'

Hence why I would like to set an attribute on the sensor so that when it is set, when the sensor does go offline, it retains it status. I really would prefer not to go the template route.

You can, build it into your template by checking the value that comes from the curl.

sensor:
  - platform: command_line
    name: eskom_loadshedding_status
    command: "curl https://loadshedding.eskom.co.za/LoadShedding/GetStatus"
    value_template: >
      {% if value.strip() %}
        {{ value | round(0) | abs - 1 }}
      {% else %}
        {{ states('sensor.eskom_loadshedding_status') }}
      {% endif %}

Sadly that didn’t solve the problem. :frowning: This is where I wish HA had variables that I could store the last status in and only update this status if the sensor is not unavailable.