How to ignore numeric value?

Problem: a “number” value sometimes is set to “0”, even though it’s invalid. See bug: "Niro AC Charging Limit" randomly set to 0 · Issue #926 · Hyundai-Kia-Connect/kia_uvo · GitHub

I want to create a helper value, that will follow the number.niro_dc_charging_limit, but ignore the “0” and keep the old value. To my surprise, it’s not that easy.

I tried to create something like trigger based value (see docs: Template - Home Assistant):

template:
  - triggers:
      - trigger: state
        entity_id: number.niro_dc_charging_limit
        not_to:
          - 0
    number:
      - name: Filtered Niro DC Charging Limit
        min: 50
        max: 100
        step: 10
        unit_of_measurement: "%"
        icon: mdi:ev-plug-ccs2
        state: "{{ states('number.niro_dc_charging_limit') }}"
        set_value: []

But I get an error:

Invalid config for ‘template’ at configuration.yaml, line 28: expected str ‘not_to->0’, got None

I guess, the “not_to” applies only to states like “unknown” or “unavailable”, but not to numeric values.

Any ideas how to proceed?

The 0 is probably a string because all entities are strings. try “0”.
But it might be “0.0” or whatever. look in the state machine and verify exactly what it is.
Open your Home Assistant instance and show your state developer tools.

I just tried “0” as a string. There are no more errors, but the value of helper is “unknown”.
The developer tool says the state of number.niro_dc_charging_limit is just 80. Hard to tell if it’s a string or not, because “unknown” above is also without quotes.

Has it changed since you loaded the new sensor? It won’t be updated until it does.

Also, remove the step 10 if the value can be 81, or round the value to a multiple of 10.

Third: are you sure you want an editable number? If is should only be updated by the trigger, you need it to be a normal sensor. It might not work if you do not supply all needed actions for number, such as set_value.

  1. I changed to source value and the helper stays undefined.

  2. Step 10 is correct.

  3. I’ll try to make it a sensor.

Changed it to sensor, restarted HA, still the value of helper is undefined.

Which brings me back to the first point I made, has the source value changed since you reloaded the latest version of the template or restarted HA?

And are you looking at number.filtered_niro_dc_charging_limit or sensor.filtered_niro_dc_charging_limit?

I changed the source value again. The helper value remains undefined.

I’m looking at sensor. The number disappeared from the list of helpers after I changed my config.

For the record, it now looks like this:

template:
  - triggers:
      - trigger: state
        entity_id: number.niro_dc_charging_limit
        not_to:
          - "0"
    sensor:
      - name: Filtered Niro DC Charging Limit
        unique_id: sensor.filtered_niro_dc_charging_limit
        unit_of_measurement: "%"
        icon: mdi:ev-plug-ccs2
        state: "{{ states('number.niro_dc_charging_limit') }}"

I think I’ll just create a helper entity and automation to update it. It’ll be a bit more convoluted, but surely will work.

Edit: This actually works! I got confused by “AC” and “DC”. After changing the correct input value, the helper entity got updated correctly.

I created this in UI:

automation:
- id: '1764011987878'
  alias: Update Filtered Niro DC Charging Limit
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - number.niro_dc_charging_limit
  conditions:
  - condition: numeric_state
    entity_id: number.niro_dc_charging_limit
    above: 50
  actions:
  - action: input_number.set_value
    metadata: {}
    data:
      value: '{{ states(''number.niro_dc_charging_limit'') }}'
    target:
      entity_id: input_number.filtered_niro_dc_charging_limit
  mode: single

:man_facepalming: I’m sorry. My sensor with trigger actually works. I confused “AC” with “DC”, therefore I was thinking I was changing the input entity, while in fact I didn’t.