Corruption of input numbers during a computation

Hello
Could someone tell me if this syntax is right ?

  - service: input_number.set_value
    metadata: {}
    data:
      value: >
        {{(states("input_number.kwh_bleu_jour")|float) +
        (states("input_number.kwh_bleu_nuit")|float) +
        (states("input_number.kwh_blanc_jour")|float) +
        (states("input_number.kwh_blanc_nuit")|float) +
        (states("input_number.kwh_rouge_jour")|float) +
        (states("input_number.kwh_rouge_nuit")|float)  }}
    target:
      area_id: edf
      entity_id: input_number.kwh_cumul

Because when I add this code to my automation, I get this :


All numbers that should be added are modified.
More even kwh_moyen is modified, this one is NOT in this automation.
Any idea ? thanks

## System Information

version | core-2024.7.3
-- | --
installation_type | Home Assistant OS
dev | false
hassio | true
docker | true
user | root
virtualenv | false
python_version | 3.12.4
os_name | Linux
os_version | 6.6.31-haos-raspi
arch | aarch64
timezone | Europe/Paris
config_dir | /config

<details><summary>Home Assistant Community Store</summary>

GitHub API | ok
-- | --
GitHub Content | ok
GitHub Web | ok
GitHub API Calls Remaining | 5000
Installed Version | 1.34.0
Stage | running
Available Repositories | 1458
Downloaded Repositories | 5
HACS Data | ok

</details>

<details><summary>Home Assistant Cloud</summary>

logged_in | false
-- | --
can_reach_cert_server | ok
can_reach_cloud_auth | ok
can_reach_cloud | ok

</details>

<details><summary>Home Assistant Supervisor</summary>

host_os | Home Assistant OS 12.4
-- | --
update_channel | stable
supervisor_version | supervisor-2024.06.2
agent_version | 1.6.0
docker_version | 26.1.4
disk_total | 13.6 GB
disk_used | 5.9 GB
healthy | true
supported | true
host_connectivity | true
supervisor_connectivity | true
ntp_synchronized | true
virtualization | 
board | rpi4-64
supervisor_api | ok
version_api | ok
installed_addons | Mosquitto broker (6.4.1), Zigbee2MQTT (1.39.0-1), Advanced SSH & Web Terminal (18.0.0), File editor (5.8.0)

</details>

<details><summary>Dashboards</summary>

dashboards | 5
-- | --
resources | 4
views | 8
mode | storage

</details>

<details><summary>Recorder</summary>

oldest_recorder_run | 22 juillet 2024 à 16:24
-- | --
current_recorder_run | 22 juillet 2024 à 18:36
estimated_db_size | 142.86 MiB
database_engine | sqlite
database_version | 3.45.3

</details>

The float filter requires a default. I put it in. Also, floats are never 100% precise. Unfortunately, the input number services do not round themselves (or in the UI) but chose to throw an error if the float not the right precision. It looks like you set it to one decimal. That input_number is picky about it is a pain, but you should be able to fix it by rounding the output:

- service: input_number.set_value
    metadata: {}
    data:
      value: >
        {{((states("input_number.kwh_bleu_jour")|float(0)) +
        (states("input_number.kwh_bleu_nuit")|float(0)) +
        (states("input_number.kwh_blanc_jour")|float(0)) +
        (states("input_number.kwh_blanc_nuit")|float(0)) +
        (states("input_number.kwh_rouge_jour")|float(0)) +
        (states("input_number.kwh_rouge_nuit")|float(0)))|round(1)  }}
    target:
      area_id: edf
      entity_id: input_number.kwh_cumul

But last but not least, the error says that the maximum range for your input number can be no bigger than 50, while the sum is more. So you need to adjest the range of the input number. I just saw toms anser and he is right. The service is now setting all input_number entities in the area :scream: So also ones with the wrong range, which lucky for you refuse.

Remove this:

Unless you want to set the value of all input numbers in that area.

1 Like

Of course, the target is only the number, no the area.
I should think more when I edit code from the graphic editor.
Thank you very much.