Slider that sends different shell commands

Hi there,

I need to make a slider from 1 to 20, and each value should run a shell command that is totally different, the slider value doesn’t need to be passed, the shell command has different HEX code, for example:

Slider value 0, echo -e “hex value A” | nc ip port
Slider value 1, echo -e “hex value B” | nc ip port
Slider value 2, echo -e “hex value C” | nc ip port
Etc.

Each HEX value is long and totally different.

Thanks in advance!

Is there any relation between the decimal slider value and the hex number you want to send?

If so you can use a mathematical template.

If not just use a list of the 20 hex values that is indexed by the slider, e.g.

'{{ ("0x0A", "0x0C", "0x11", ... "0x34")[states('input_number.your_slider')|int] }}'

Substitute that for the hex value in your command.

Write an automation that triggers on any change of state of the slider (state trigger with no to or from) that calls your command.

1 Like

Could you please point me on what code to put slider code and where (I think in configuration.yaml), and code base for the automation that triggers the change in slider please?

Can you supply the list of hex values in the order of their corresponding 0-20 slider values?

Also what is this controlling (so I can make up some names / entity ids)?

The command I need to send is:

echo -e "HEX value" | nc 192.168.1.196 5200

Here’s the list of HEX values from 0 to 20:

Black,\x55,\xAA,\x00,\x00,\xFE,\x00,\x00,\x00,\x00,\x00,\x01,\x00,\x50,\x00,\x20,\x02,\x01,\x00,\x02,\xC9,\x56
5%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x0D,\x62,\x5A
10%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x1A,\x6F,\x5A
15%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x27,\x7C,\x5A
20%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x33,\x88,\x5A
25%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x40,\x95,\x5A
30%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x4D,\xA2,\x5A
35%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x5A,\xAF,\x5A
40%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x66,\xBB,\x5A
45%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x73,\xC8,\x5A
50%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x80,\xD5,\x5A
55%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x8D,\xE2,\x5A
60%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x9A,\xEF,\x5A
65%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xA6,\xFB,\x5A
70%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xB3,\x08,\x5B
75%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xC0,\x15,\x5B
80%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xCD,\x22,\x5B
85%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xDA,\x2F,\x5B
90%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xE6,\x3B,\x5B
95%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xF3,\x48,\x5B
100%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xFF,\x54,\x5B

What about using shell_command for this? How could I trigger proper shell command from a slider?

novastar_brightness_0: echo -e "\x55,\xAA,\x00,\x00,\xFE,\x00,\x00,\x00,\x00,\x00,\x01,\x00,\x50,\x00,\x20,\x02,\x01,\x00,\x02,\xC9,\x56" | nc 192.168.1.196 5200
novastar_brightness_1: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x0D,\x62,\x5A" | nc 192.168.1.196 5200
novastar_brightness_2: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x1A,\x6F,\x5A" | nc 192.168.1.196 5200
novastar_brightness_3: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x27,\x7C,\x5A" | nc 192.168.1.196 5200
novastar_brightness_4: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x33,\x88,\x5A" | nc 192.168.1.196 5200
novastar_brightness_5: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x40,\x95,\x5A" | nc 192.168.1.196 5200
novastar_brightness_6: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x4D,\xA2,\x5A" | nc 192.168.1.196 5200
novastar_brightness_7: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x5A,\xAF,\x5A" | nc 192.168.1.196 5200
novastar_brightness_8: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x66,\xBB,\x5A" | nc 192.168.1.196 5200
novastar_brightness_9: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x73,\xC8,\x5A" | nc 192.168.1.196 5200
novastar_brightness_10: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x80,\xD5,\x5A" | nc 192.168.1.196 5200
novastar_brightness_11: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x8D,\xE2,\x5A" | nc 192.168.1.196 5200
novastar_brightness_12: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x9A,\xEF,\x5A" | nc 192.168.1.196 5200
novastar_brightness_13: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xA6,\xFB,\x5A" | nc 192.168.1.196 5200
novastar_brightness_14: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xB3,\x08,\x5B" | nc 192.168.1.196 5200
novastar_brightness_15: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xC0,\x15,\x5B" | nc 192.168.1.196 5200
novastar_brightness_16: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xCD,\x22,\x5B" | nc 192.168.1.196 5200
novastar_brightness_17: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xDA,\x2F,\x5B" | nc 192.168.1.196 5200
novastar_brightness_18: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xE6,\x3B,\x5B" | nc 192.168.1.196 5200
novastar_brightness_19: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xF3,\x48,\x5B" | nc 192.168.1.196 5200
novastar_brightness_20: echo -e "\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xFF,\x54,\x5B" | nc 192.168.1.196 5200

Input number:

my_slider:
  name: my slider
  min: 0
  max: 20
  step: 1

Automation:

trigger:
  platform: state
  entity_id: input_number.my_slider
action:
  service: "shell_command.send_hex_{{ states('input_number.my_slider')|int }}"

Shell commands (20 of them):

send_hex_0: echo -e "Black,\x55,\xAA,\x00,\x00,\xFE,\x00,\x00,\x00,\x00,\x00,\x01,\x00,\x50,\x00,\x20,\x02,\x01,\x00,\x02,\xC9,\x56" | nc 192.168.1.196 5200
send_hex_1: echo -e "5%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x0D,\x62,\x5A" | nc 192.168.1.196 5200
send_hex_2: echo -e "10%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\x1A,\x6F,\x5A" | nc 192.168.1.196 5200
...
send_hex_20: echo -e "100%,\x55,\xAA,\x00,\x00,\xFE,\xFF,\x01,\xFF,\xFF,\xFF,\x01,\x00,\x01,\x00,\x00,\x02,\x01,\x00,\xFF,\x54,\x5B" | nc 192.168.1.196 5200
1 Like

Your code worked perfectly! Thanks a lot!

Note: my code had problem with the HEX codes, I removed the commas and now it works.