Run script based on slider percentage

Ok so I have my input_number. Let’s assume I’m able to figure out how to create the automation I need for a specific speed.

How do I tie that into a slider? That’s the part im having the most trouble with

Automation Basics
UI Automation Editor
Automation YAML

There are many ways to do what you want in an automation. Based on what you have posted, one way to do it would be something like the following… (make sure you insert the values for the commands in the variables section)

trigger:
  - platform: state
    entity_id: input_number.fan_slider
    for: "00:00:02"
condition: []
action:
  - variables:
      vol_level: "{{ trigger.to_state.state | float(0) }}"
      command: >
        {% if vol_level == 0 %}
        
        {% elif vol_level > 80 %}
          6
        {% elif vol_level < 40 %}
        
        {% else %}
        
        {% endif %}
  - service: remote.send_command
    data:
      device: cigar_fan
      command: "{{ command }}"
    target:
      entity_id: remote.wi_fi_universal_remote_remote

My God you solved it for
Me . I’m literally nauseous I’ve been working on this for so long lol

Thank you.

Happy to help… FWIW, you can probably lower the for: on the trigger to 1 second instead of 2. Having a for: defined helps keep the automation actions from executing too often when you are using the slider to change the value, but there’s always a balance to figure out between how “bouncy” and how “laggy” you are willing to have an automation act.

Cool cool thanks again

Before you go, please consider marking Didgeridrew’s helpful post with the Solution tag. It will help others find answers to similar questions.

For more information, refer to guideline 21 in the FAQ.

Please mark Didgeridrew’s post with the Solution tag (not my post).

My bad lol all set

Hey would you be able to show me your mushroom card code for this? Trying to do the exact same thing but struggling to figure out how I can have my 5 speed DC fan controlled via Broadlink use the slider

type: custom:restriction-card
restrictions:
  confirm:
    block: true
card:
  type: custom:stack-in-card
  cards:
    - type: custom:mushroom-template-card
      primary: Fan
      secondary: |
        {% set vol_level = states(entity) | float %}
        {% if vol_level == 1 %}
          Off
        {% else %}
        {% set vol = states(entity) | float * 1 %}
        {{ vol | round | int }}%
        {% endif %}
      icon: mdi:fan
      icon_color: |
        {% set vol_level = states(entity) | float %}
        {% if vol_level == 1 %}
          #696969
        {% else %}
          indigo
        {% endif %}
      entity: input_number.fan_slider
      tap_action:
        action: call-service
        service: script.cigar_fan_off
        data: {}
        target: {}
      card_mod:
        style:
          mushroom-shape-icon$: |
            ha-icon {
              --icon-animation: rotation {{ 5 / states(config.entity) | float * 10 }}s linear infinite;
            }
                @keyframes rotation {
              100% {
                transform: rotate(360deg);
              }
            }
    - type: custom:my-slider-v2
      entity: input_number.fan_slider
      styles:
        card:
          - height: 42px
        container:
          - border-radius: 12px
        track:
          - background: >
              [[[ if (entity.state == "off") return
              "rgba(var(--mush-rgb-disabled), 0.2)";
               else return "rgba(120, 120, 120, 0.2)";
              ]]]
        progress:
          - background: >
              [[[ if (entity.state == "off") return
              "rgb(var(--mush-rgb-disabled))";
               else return "rgb(var(--mush-rgb-indigo))";
              ]]]
        thumb:
          - width: 0px
      card_mod:
        style: |
          ha-card {
            padding: 0px 12px 12px;
            --mush-rgb-disabled: 189,189,189;
            --mush-rgb-indigo: 63, 81, 181;
          }

Hello. Disregard the restriction card part. It’s an exhaust fan that I can’t hear from a certain part of my house so I have this to prevent me from turning it on by accident.

Thanks so much James - keen to give this a try tonight

Happy to help :slight_smile:

Hey James,
I’ve replaced ‘script.cigar_fan_off’ to ‘script.master_fan_power’ (because that’s my RF script for fan power)
and removed the top stuff re exhaust fan, however while I’m not getting errors in code, I’m just getting a blank mushroom card when I save it. Did you do anything else outside of creating the mushroom fan card to get this to work?

Did you create the input_number entity, under helpers? That’s the only thing I can think of that will be preventing this from working aside from a typo.

Oops. No, thanks!

Ok, Ive now got the slider working and my input_number.fan slider automation set up, however every time I move the slider on my dashboard i get an error of: failed to call service fan/set percentage
is the percentage slider now deprecated with an update HA? or its more likely Ive got something wrong

So I have separate scripts for each of my fan speeds. Needed to do that because it’s RF and I’m using the BroadLink hub. So I set up automations one for each range.

Example: when slider is 1-17%, trigger script 1, which is the first fan speed.

See if that info helps you. I’m not exactly sure what your setup is.

Yeap I’ve done the same too - one for each speed.


Actually, what should I have in my trigger? this?