How to set counter or input number to a negative value?

How do you set a counter or input number to a negative value? Parameter field doesn’t accept negative values but still I can set them with slider or increment/decrement setting and in counter settings specify lowest value to negative. So what is going on, how do I set them to negative with a script/automation?

I just tried putting a negative number In a Dev Tools service call and it worked ok. I first ensured the helper had a minimum value that was negative.

image

Doesn’t work here. The counter has minimum value of -20. I tried this:
set

and got this error:

They used an input_number, which does allow negative values. Counters do not. You can vote for the request to allow this here:

I did try also with input numbers earlier, but I guess something was wrong in my settings. Tried again and now it worked.

Did more testing: setting negative input number with input_number.set_value works only with scripts. It doesn’t seem to work when used in automations.
There appears a mousetip message that the value must be at least 0. You can still put negative values there, but they are not working i.e. the input number doesn’t change.

Automation actions are identical to script sequences.

So then why it is not working with automations? Did you try it or just assumed it should be identical?

No need to assume anything. That’s how it is.

I just tested it in an automation and it worked as expected.

input_number:
  test:
    name: test input number
    initial: 0
    min: -20
    max: 100
    step: 1

automation:
  - alias: set input number to minus
    trigger:
      - platform: state
        entity_id: input_boolean.bool_13
        to: 'on'
    action:
      - service: input_number.set_value
        entity_id: input_number.test
        data:
          value: -2

OK, so it works with manually entered -20. But it shows red underline for an error in the value and mousetip saying that the value must be at least 0.
If I try to change the value with mouse, it jumps to 0 and won’t go down (unless the value is again manually entered).

When you created the Input Number helper, what value did you specify for its min option? For your application, the value of min should be negative (not 0).

you’re going to need to give us more info on how the input number is configured and show us the automation you are using that’s failing.

post text. not screenshots.

I did specify -20 for min value.

Automation is now working. But there is something weird going on with negative values in the UI. I’ll have to check with a different browser (currently using Edge).

1 Like

I just created an Input Number helper with min set to -20 and max to 100.

I can set its value in the UI to a negative value up to and including -20 without any ‘red underline’ appearing.

Screenshot from Edge browser.

Red underline and mousetip appears in the scripts and automations editor.
.


Now I understand where you’re looking.

I see the same thing but the Automation Editor allows saving it anyway and preserves the negative value.

Welcome to the many quirks of the Automation Editor. Feel free to report it as a bug in Home Assistant’s GitHub Frontend repository.