What I am trying to do is to link an input slider to 10 different scripts. So for example when the slider’s value is 1 I want to trigger a script, if the sliders value is 2 then activate another script and so on.
An example of the script i would like to trigger is:
script:
amp_mute:
alias: Mute
sequence:
- service: broadlink.send_packet_192_168_1_79
data:
packet:
-“JgBgADEAAZQLaAhkCycQYgwkFRsbHRtbEBscHB5VGRofJRFRHxkeUBxSG1QdGBwABKFubh5RH08dGxxTHlAeGhxSHRsdGh0bHk4cGx8ZHVEdGx4aHVIcGh1SHFMcUxwYHQANBQAAAAAAAAAA”
I think you would have to do it with 10 different automations…or, it might be a good application for one of the new python scripts.
You could trap a change to the input slider, and as the action, have the python script get the state of the slider, and then go through an if elif condition to decide what to do off of each state… That might work…
Haven’t tested that, but maybe you can use templating to select the script to launch.
If you have your input slider from 1 to 10, and your scripts named my_script_number_1, my_script_number_2, etc…
Something like this:
First off please use preformatted text for configs. Also we would need a bit more info here. Could you post the config of all components involved (Not the scripts obviously)? Right now I can’t understand where 'brightness ’ comes from.
quinled_kitchen_100: sh /home/homeassistant/.homeassistant/shell_commands/quinled_kitchen_100.sh
quinled_kitchen_75: sh /home/homeassistant/.homeassistant/shell_commands/quinled_kitchen_75.sh
quinled_kitchen_50: sh /home/homeassistant/.homeassistant/shell_commands/quinled_kitchen_50.sh
quinled_kitchen_35: sh /home/homeassistant/.homeassistant/shell_commands/quinled_kitchen_35.sh
quinled_kitchen_15: sh /home/homeassistant/.homeassistant/shell_commands/quinled_kitchen_15.sh
quinled_kitchen_00: sh /home/homeassistant/.homeassistant/shell_commands/quinled_kitchen_00.sh
OK - so if I run below as suggested I have figured out that the slider value is 1.0 / 2.0 / etc and not just 0 / 1 / etc. Getting an error on the first command that I am not sure how to correct.
{{ if states.input_slider.kitchen_brightness.state == 5.0 }}
When moving my slider it is not invoking the scripts, and I suspect its because I am not getting a “true” with below commands… but not sure how to troubleshoot further…
{% if states.input_slider.kitchen_brightness.state == "5.0" %}
shell_command.quinled_kitchen_100
{% elif states.input_slider.kitchen_brightness.state== "4.0" %}
shell_command.quinled_kitchen_75
{% elif states.input_slider.kitchen_brightness.state== "3.0" %}
shell_command.quinled_kitchen_50
{% elif states.input_slider.kitchen_brightness.state== "2.0" %}
shell_command.quinled_kitchen_35
{% elif states.input_slider.kitchen_brightness.state== "1.0" %}
shell_command.quinled_kitchen_15
{% elif states.input_slider.kitchen_brightness.state== "0.0" %}
shell_command.quinled_kitchen_00
{% else %}
//NOTIFY YOURSELF because this should not happen
{% endif %}
or use
{% if states.input_slider.kitchen_brightness.state | int == 5 %}
shell_command.quinled_kitchen_100
{% elif states.input_slider.kitchen_brightness.state | int == 4 %}
shell_command.quinled_kitchen_75
{% elif states.input_slider.kitchen_brightness.state | int == 3 %}
shell_command.quinled_kitchen_50
{% elif states.input_slider.kitchen_brightness.state | int == 2 %}
shell_command.quinled_kitchen_35
{% elif states.input_slider.kitchen_brightness.state | int == 1 %}
shell_command.quinled_kitchen_15
{% elif states.input_slider.kitchen_brightness.state | int == 0 %}
shell_command.quinled_kitchen_00
{% else %}
//NOTIFY YOURSELF because this should not happen
{% endif %}
if you are sure there are only integers coming from that slider I think the second would be the best. Also please replace //NOTIFY YOURSELF because this should not happen with an actual service call
~Cheers
PS: The reason for this is that the state seems to return a string…and you compare it with numbers the double quotes tell the jinja2 engine that it is a string and the | int tells the engine that it should convert what comes before it into an integer.
Did you manage to get your input_slider / input_number to function correctly? If so could you share the workings as I have a need for the same functionality to control 2 relays.