Slider logic

Im building a replica of the Hue Dimmer switch, using my own ESP based wall mounted switches. In the project, I need to control a slider, that will be used for dimming the hue lights later on. When I press a key on the switch the slider must increment 25, or decrements 25 depending on witch button. I have it working, exept the logic for decremented the slider,

I have build in some tests so it always goes to zero.it does not exceed the boundaries (0-255), and it is in this test, it will not detect that the slider has a value, and just set it to 0. (automation test hue 3:)

Any help is appreciated

automation test hue 2:
  - alias: Set temp slider
    trigger:
       platform: state
       entity_id: input_boolean.3_short
       to: 'on'
    action:
       service: input_slider.select_value
       data_template:
        entity_id: input_slider.slider1
        value: >
           {% if states('input_slider.slider1.state') | float + 25 <= 255 %}
              {{ states.input_slider.slider1.state | int + 25 }}
           {% else %} 
              {{ 255 | int }}
           {% endif %} 
        
automation test hue 3:
  - alias: Set temp slider
    trigger:
       platform: state
       entity_id: input_boolean.3_long
       to: 'on'
    action:
       service: input_slider.select_value
       data_template:
        value: >
           {% if states('input_slider.slider1.state') | float - 25 >= 0 %}
              {{ states.input_slider.slider1.state | int - 25 }}
           {% else %} 
              {{ 0 | int }}
           {% endif %}   

Only thing I noticed is that you have two

  • alias: Set temp slider

I’m not sure if it will make a difference, was there any errors in the log?

I solved the issue. The problem was the .state that need to be there when the script reads the value, and not when it write, working solution here:


- alias: Set slider_spisebord up
  trigger:
    platform: state
    entity_id: input_boolean.3_short
    to: 'on'
  action:
    service: input_slider.select_value
    entity_id: input_slider.slider_spisebord
    data_template:       
      value: >
        {% if (states('input_slider.slider_spisebord') | int + 75) <= 255 %}
          {{ states.input_slider.slider_spisebord.state | int + 75 }}
        {% else %} 
          {{ 255 | int }}
        {% endif %}   

- alias: Set slider_spisebord down
  trigger:
    platform: state
    entity_id: input_boolean.3_long
    to: 'on'
  action:
    service: input_slider.select_value
    entity_id: input_slider.slider_spisebord
    data_template:       
     value: >
        {% if (states('input_slider.slider_spisebord') | int - 75) >= 0 %}
           {{ states.input_slider.slider_spisebord.state | int - 75 }}
        {% else %} 
           {{ 0 | int }}
        {% endif %}