2023.5 error on null for filter entity

I have some sensor filter entities which deliberately set to null in some instances, so that apex-charts ignores the value and do not display them when they are not active (setting them to 0 results in Apexcharts showing the line at 0).

E.g.:

#### Sensor entity for graphs - null if 0
      - name: "Grid peak power graph"
        unit_of_measurement: 'W'
        device_class: power
        state_class: measurement
        state: >-
          {% if 
            states('input_text.utility_current_electricity_tou_band') in ['shoulder', 'offpeak']
          %}
            null
          {% else %}
            {{
              states('sensor.grid_peak_power')
            }}
          {% endif %}
        unique_id: 2452716747769

The intention is that the entity has a value when the time of use band is active only, and null when it is not.

In 2023.5 the log now throws an error, and refuses to set the entity to null:

Sensor sensor.grid_peak_power_graph has device class power, state class measurement unit W and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: null (<class 'str'>)

Now it retains the value it last had, so in this instance it results in a totally messed up graph (red line should not be there):
image

I acknowledge that setting it to null is a workaround to make Apexcharts ignore it. Is there a better way?

Yes use the availability template option instead.

#### Sensor entity for graphs - null if 0
      - name: "Grid peak power graph"
        unit_of_measurement: 'W'
        device_class: power
        state_class: measurement
        state: "{{ states('sensor.grid_peak_power') }}"
        availability: "{{ states('input_text.utility_current_electricity_tou_band') not in ['shoulder', 'offpeak'] }}"
        unique_id: 2452716747769

Or depending on your input text states,

availability: "{{ is_state('input_text.utility_current_electricity_tou_band', 'peak') }]"
1 Like

I have a suspicion that I tried that originally and apexcharts didn’t react as expected… but I’ll try it again, it may have changed.