Hello,
I have been trying to pass a value from a input_number to a shell_command in many different ways without succeeding. Could anyone please guide me?
configuration file
input_number:
hall_slider:
name: Hall_Brightnes
initial: 13
min: 0
max: 15
step: 1
mode: slider
####### Shell commands
shell_command:
set_dimval: 'echo Value = {{ states.input_number.hall_slider.state }} >> /home/homeassistant/text.txt'
Automation file:
- alias: Hall_Brightnes
trigger:
platform: state
entity_id: input_number.hall_slider
action:
- service: shell_command.set_dimval
When I remove the {{ **** }} from the shell command and replace with a fix value I can see that the command is executed when the slider is moved. But when I try to pass a value nothing seems to happen.
Thank you in advance!
I think your issue may be due to this (from the doc page):
When using templates, shell_command runs in a more secure environment which doesn’t allow any shell helpers like automatically expanding the home dir ~
or using pipe symbols to run multiple commands.
It may be that the stdout redirection doesn’t work when using templates. Not sure.
You might get some more insight into what’s happening by enabling debug for the shell command:
logger:
default: info
logs:
homeassistant.components.shell_command: debug
Then look in home-assistant.log.
Thanks for the reply. I am not using a relative path so should not be a problem with ~. But I will try to change the debug level to see if there is a useful output.
My point was >>
might not work since you’re using a template. I’m not saying it won’t work, I’m just saying it might not work.
Sorry I misunderstood you. Will try it a different way without stdout.
Thanks
Did you get anywhere with this? I’m trying to do the same and not getting very far at the moment
In my case I used it for controlling a light, and the end solution looked like this:
Lights file
- platform: template
lights:
hallway_light:
friendly_name: "Hallway Light"
turn_on:
- service: shell_command.switch433
data_template:
unit: "hall"
power: "on"
turn_off:
- service: shell_command.switch433
data_template:
unit: "hall" #change this
power: "off"
set_level:
- service: shell_command.dimmer433
data_template:
unit: "hall" #change this
power: "on"
dimlevel: "{{ (brightness | float / (255/15)) | int }}"
shell_command.yaml
dimmer433: /path/light_control.sh --name {{unit}} --state {{power}} --bri {{dimlevel}}
switch433: /path/light_control.sh --name {{unit}} --state {{power}}
1 Like