Adding a plus/minus button for number entity

Hello there!
I use mushroom-number card, I want to add minus and plus to the right and left of the slider so that I can change the value of the mushroom-number to plus or minus 5% (step).
image
I suppose I need to enter some code in “value”, but I tried a lot of things and I can’t imagine what it should look like…
Here is an example of code that I’m using for plus button:

      - show_name: false
        view_layout:
          grid-area: right
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: number.set_value
          target:
            entity_id:
              - number.ustavka_uvlazhneniia
          data:
            value: '{{ state_attr(number.ustavka_uvlazhneniia, ''value'') + step}}'
        entity: number.ustavka_uvlazhneniia
        icon: mdi:plus
        theme: minimalist-desktop

There’s a few things that needs to be changed.
I believe something like this:

      - show_name: false
        view_layout:
          grid-area: right
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: number.set_value
          target:
            entity_id:
              - number.ustavka_uvlazhneniia
          data:
            value: '{{ state_attr("number.ustavka_uvlazhneniia", ''value'') + 5}}'
        entity: number.ustavka_uvlazhneniia
        icon: mdi:plus
        theme: minimalist-desktop

I believe this should work

Surely:

          data:
            value: '{{ states("number.ustavka_uvlazhneniia")|int + 5}}'

The number is the state of the entity not a value attribute. Is this a ChatGPT hallucination?

Yes… I didn’t notice that.

Not ChatGPT, just tryed everything that I could :slight_smile:
And now I got this…
image
This is an KNX entity with these types of values, maybe it could help:

    - name: "ustavka_uvlazhneniia"
      address: "2/7/0"
      state_address: "2/7/1"
      type: humidity
      respond_to_read: true
      min: 0
      max: 70
      step: 5
      mode: box

Are you able to adjust this number from the entity details box? Are you sure it’s not read-only?

Please post a screenshot from Developer Tools/ States showing the entity, its state and attributes.

Yeah, sure:


Ofcourse it’s not read-only.
And more than that, in details of the entity I can change the value of the number to plus or minus 5% (step):
image

There are 2 single-quotes ' where it should be double-quotes " around “value”

Didnt work, same error:

You can’t use templates in tap actions. You must call a script to do the adjustment.

1 Like

oh, and now I see
value: '{{ state_attr(number.ustavka_uvlazhneniia, "value") + step}}' is looking for a state attribute called value - there is none though… see the screenshot above of dev-tools States.
You probably want
value: '{{ states("number.ustavka_uvlazhneniia") | int + step }}' or something like that to get the value of the state, cast it to int and add the step value (which I don’t know where it comes from).

You can just test your templates in developer tools if you are uncertain if something works. You’ll get live results there. Open your Home Assistant instance and show your template developer tools.

Like I said above: Adding a plus/minus button for number entity - #3 by Troon

But it won’t work anyway as you can’t have templates in actions.

2 Likes

Alternative: :slight_smile:

EDIT:

Add the ability to increase or decrease the value of a number entity with a single service call instead of having to call the number.set_value service using a template that does calculations on the current state.

Thanks a lot! Now it works perfectly :slight_smile:

1 Like