Hi,
I am trying to set my AC to any temperature using an input slider and IR commands but unable to do it.
I can turn ON and OFF the AC using scripts but changing the temperature using the input slider is not working for me can you help me in that.
Post your automation/config so that we can help debug. (Use preformatted text, btw).
Confirm that your IR commands to change temp work when set manually (use the services dev tool to test).
Yes IR commands are working manually. The configuration.yaml file is below.
automation:
- alias: run_set_ac
trigger:
platform: state
entity_id: input_slider.ac_temperature
action:
service: script.set_ac_to_slider
input_slider:
ac_temperature:
name: A/C Setting
initial: 24
min: 20
max: 24
step: 2
the script.yaml file
set_ac_to_slider:
alias: AC ON
sequence:
- service: shell_command.set_ac_to_slider
ac_off:
alias: AC OFF
sequence:
- service: shell_command.ac_off
the shell commmand.yaml file
ac_off: irsend SEND_ONCE Orientac OFF
set_ac_to_slider: 'irsend SEND_ONCE Orientac ACon_{{ states.input_slider.ac_temperature.state }}'
You may need {{ states.input_slider.ac_temperature.state | int}} as i think it defaults to float
Try just using a variable in the shell command and pass the input slider value to the shell command from your script instead. I know that way should work, I haven’t tried it the way you are doing it personally. @ih8gates example above should work. Pass value to command line
Thanks for your kind help. But I have done it the other way
You’re not actually doing it like in my example. I’m passing the variable via a data_template. I’m not sure if any template value is valid there.
Try passing the script a value from the automation’s action like in my example.
thanks for your help but i have done it without using automation action
I’m trying to use the shell command with an input select, to change the predefined heat programs of my Buderus central heating unit. The Buders KM271 serial board is configured with a stand alone FHEM instance, where i can send commands via telnet to.
So what I want to do is, to pass the input select value to the shell command and use the value to chance the heat program and use an automation to trigger the service.
- action:
- service: shell_command.set_heatprogramm
alias: run_set_heatprogramm
condition:
id: ‘1510046601796’
trigger:- entity_id: input_select.heatprogramm_select
platform: state
To change the FHEM values via telnet I use netcat (nc) to send the commands to FHEM, but I have no idea how to escape the state of the input select so thats inside the command line.
shell_command:
set_heatprogramm: ‘echo “set Buderus hk1_programm {{ states.input_select.heatprogramm_select.state }}” | nc 192.168.x.x 7072’
Due to the fact that i have to use " to send the whole set … string to fhem with netcat i have to include the input select state in which kind of formatting?
Logfile after selection:
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=option=frueh, entity_id=input_select.heatprogramm_select, service=select_option, service_call_id=1973120752-35, domain=input_select>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state input_select.heatprogramm_select=mittag; friendly_name=Heizprogramm, options=[‘eigen’, ‘familie’, ‘frueh’, ‘mittag’, ‘nachmittag’, ‘senior’, ‘single’, ‘spaet’, ‘vormittag’] @ 2017-11-07T10:46:59.973644+01:00>, entity_id=input_select.heatprogramm_select, new_state=<state input_select.heatprogramm_select=frueh; friendly_name=Heizprogramm, options=[‘eigen’, ‘familie’, ‘frueh’, ‘mittag’, ‘nachmittag’, ‘senior’, ‘single’, ‘spaet’, ‘vormittag’] @ 2017-11-07T11:09:53.275219+01:00>>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.components.automation] Executing run_set_heatprogramm
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: message=has been triggered, name=run_set_heatprogramm, domain=automation, entity_id=automation.run_set_heatprogramm>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.helpers.script] Script run_set_heatprogramm: Running script
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.helpers.script] Script run_set_heatprogramm: Executing step call service
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=, service=set_heatprogramm, service_call_id=1973120752-36, domain=shell_command>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1973120752-35>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1973120752-36>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state automation.run_set_heatprogramm=on; friendly_name=run_set_heatprogramm, id=1510046601796, last_triggered=2017-11-07T10:47:00.068473+01:00 @ 2017-11-07T10:23:24.406207+01:00>, entity_id=automation.run_set_heatprogramm, new_state=<state automation.run_set_heatprogramm=on; friendly_name=run_set_heatprogramm, id=1510046601796, last_triggered=2017-11-07T11:09:53.357611+01:00 @ 2017-11-07T10:23:24.406207+01:00>>
Here is my code:
action:
- service: shell_command.enter_task
data_template:
value: >
{{states.input_text.daily_schedule_task_input.state}}
shell_command:
enter_task: ‘echo {{ value }}>>/home/homeassistant/.homeassistant/schedule’
input_text:
daily_schedule_task_input:
name: Input task
Basically it is the same as yours. Tried every possible thing I could, but it just doesn’t work. If I remove {{value}} from the shell_command, it works fine, but as soon as I try to input any varibale/parameter in the command line, its not working.
PS. Ignore the indentation, they are correct, checked them several times. I just don’t know how to enter the code in the format as you did in your comment. New here
Do you need a space between the value and the redirection?
shell_command:
enter_task: ‘echo {{ value }} >> /home/homeassistant/.homeassistant/schedule’
bump
no templating within shell commands command_line is dumb and driving me nuts.
This was fixed 3 years ago - if it’s not working for you, create a new thread with your code for someone to have a look at, or if you’re 100% confident that your code is correct, report it as a bug.
While this is an old topic, maybe someone can help.
What if I am using
- curl as a shell command
- The curl request takes a JSON payload, and
- I want to template what is inside the payload
So I have this:
vizio_processkey: 'curl -k -H "Content-Type: application/json" -H "AUTH: XXXXXXXX" -X PUT -d "{\"KEYLIST\": [{\"CODESET\": {{ codeset }},\"CODE\": {{ code }},\"ACTION\":\"KEYPRESS\"}]}" https://###.###.###.###:7345/key_command/'
Where {{ codeset }}
and {{ code }}
should be passed in. I know the command works because I can just hardcode codeset as ‘5’ and code as ‘0’ and the volume goes down.
So the general question is how does the templating engine distinguish (or can I make it happen) a {{ }}
variable when building a JSON payload?
Did you try the listed solution on this thread? Because its literally showing how to do what you’re trying to do.
I did (more or less) and after some additional debugging I have found the issue which I solved.
First instead of command_line “curl” I changed to a “rest_command” … I did this mostly because I wanted to control things a bit better.
Then I realized what the real error is … when passing around variables it seems as they are strings (which in the listed example they all are strings anyway). So I changed the template to {{ codeset | int }}
and it functions correctly. If the JSON payload is expecting an INT value then you must specifically make it one.
So now I have a totally functional Vizio remote control like this:
With a rest_command template like this:
vizio_processkey:
url: "https://###.###.###.###:7345/key_command/"
method: put
content_type: "application/json"
headers:
AUTH: XXXXXXXX
payload: '{"KEYLIST": [{"CODESET": {{ codeset | int }},"CODE": {{ code | int }},"ACTION":"KEYPRESS"}]}'
verify_ssl: false
Now delving into handling the IP address(es) and auth codes for all the televisions.