Script to add or subtract number to existing slider

Hi guys,

I’m struggling to get a couple of scripts working. After googling around and looking at the script documentation - i’ve got to this point:

  add_10_to_slider1:
    sequence:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.slider1
          value: '{{ states.input_number.slider1.state + 10 }}'

I’m using similar code in my automations which works, but i can’t seem to get the code/formatting correct for the script.

any advice or recommendations welcome!

thanks :slight_smile:

How about this?

value: '{{ states('input_number.slider1') | int + 10 }}'

thanks man that did it :smiling_face_with_three_hearts:

1 Like

Just make sure you use this if you use toms solution. Gotta make sure your quotes are set up properly. quotes inside quotes only work if they are different quote times, I.e. singles can’t go in singles, doubles can’t go in doubles. Notice how the template below is all red? that’s because the whole thing is a string where as the other one posted has black, which will try to evaluate that as a method/function.

value: "{{ states('input_number.slider1') | int + 10 }}"

or use the multiline notation, to prevent all issues, at all times:

value: >
  {{ states('input_number.slider1') | int + 10 }}

Dammit. You’d think I’d stop making these silly mistakes by now.

Thanks for fixing it.