iway
(Chris)
February 9, 2021, 4:55pm
1
Hi all!
I am trying to set up a command line switch that provides an input value like this:
- platform: command_line
switches:
pool_target_temp:
command_on: |
echo '{"command":"SetParamList","messageID":"1234","objectList":[{"objnam":"B1101","params":{"LOTMP":" {{ ((states.input_number.poolsetpointtemp) | int) }} "}}]}' | nc 192.168.xxxxxx 6681
It should set the input_number.poolsetpointtemp value into the command above. But it does not.
This works to set it to 61:
echo '{"command":"SetParamList","messageID":"1234","objectList":[{"objnam":"B1101","params":{"LOTMP":"61"}}]}' | nc 192.168.3.112 6681
Any idea how to make it work?
Thanks!
JTPublic
(JT)
February 9, 2021, 5:46pm
2
" {{ ((states.input_number.poolsetpointtemp) | int) }} "
Try adding .state and remove the spaces after the 1st " and before the last " :
“{{ ((states.input_number.poolsetpointtemp.state) | int) }}”
iway
(Chris)
February 9, 2021, 7:39pm
3
No, does not work either.
tom_l
February 9, 2021, 7:58pm
4
Same question, just yesterday.
The command line switch does not accept templates. However the shell command does:
So you could do something like this:
shell_command:
play_mp3: "/usr/bin/curl -g 'http://192.168.24.201:88/play.php?argument1={{ filename }}'"
To use this you could set up Lovelace buttons with the following tap action:
tap_action:
action: call-service
service: shell_command.play_mp3
service_data:
filename: horn.mp3
You’re not limited to buttons either. See:
You could use album artwork in a pi…
You should use this format for your template to prevent errors if the input number is uninitialised:
{{ states('input_number.poolsetpointtemp') | int }}
iway
(Chris)
February 9, 2021, 8:35pm
5
shell_command:
pool_setpoint_activate: printf '{"command":"SetParamList","messageID":"1234","objectList":[{"objnam":"B1101","params":{"LOTMP":"{{ states('input_number.poolsetpointtemp') | int }}"}}]}' | nc 192.168.xxx.xxx 6681
Is not working.
shell_command:
pool_setpoint_activate: printf '{"command":"SetParamList","messageID":"1234","objectList":[{"objnam":"B1101","params":{"LOTMP":"86"}}]}' | nc 192.168.xxx.xxx 6681
That works. But not with the variable in it.
tom_l
February 9, 2021, 8:40pm
6
It’s likely to be a problem with the single quotes in the template interfering with the single quotes outside the shell command. Try it using this:
pool_setpoint_activate: printf '{"command":"SetParamList","messageID":"1234","objectList":[{"objnam":"B1101","params":{"LOTMP":"{{ states(''input_number.poolsetpointtemp'') | int }}"]}' | nc 192.168.xxx.xxx 6681
tom_l
February 9, 2021, 8:48pm
8
I just edited my post. Try again.
iway
(Chris)
February 9, 2021, 8:54pm
9
Just did, sorry, still does not work. Is there some way to see the actual output?
tom_l
February 9, 2021, 8:55pm
10
The developer tools template editor.
iway
(Chris)
February 9, 2021, 9:31pm
11
Looking fine in the template editor, with just (“input_number.poolsetpointtemp”) (not ’ ').
But it does not work, unfortunately.
iway
(Chris)
February 9, 2021, 9:34pm
13
Sure:
echo ‘{“command”:“SetParamList”,“messageID”:“1234”,“objectList”:[{“objnam”:“B1101”,“params”:{“LOTMP”:“86”}}]}’ | nc 192.168.3.112 6681
docsparks
(Docsparks)
February 9, 2021, 10:36pm
14
I hope i save the day on this one. I had a nightmare of a time the past year trying to figure something out , that I know nothing about.
temp_value2: /bin/bash -c "echo '{{ value }}' > /dev/ttyACM0"
temp_value3: /bin/bash -c "echo '{{ states.input_text.usbtext.state }}' > /dev/ttyACM0"
temp_value4: /bin/bash -c "echo '{{ value }}' >> /dev/ttyACM0"
temp_io1: /bin/bash -c "echo -n '{{ states.input_text.usbtext.state }}' >> /dev/ttyACM1"
temp_io2: /bin/bash -c "echo -e '{{ states.input_text.usbtext.state }}' >> /dev/ttyACM1"
temp_io3: /bin/bash -c "echo -e -n '{{states('input_text.usbtext')}}'>> /dev/ttyACM1"
see that /bin/bash before everything? that was what i was missing, while trying every variation possible, I had to make an arduino with lcd at one point to see exactly what was being received because the logging process… for a 2 year newb, is the worst. template editor always showed correct, however what was sent, was far from it.
hope that helps!
1 Like
iway
(Chris)
February 10, 2021, 9:29am
15
Thanks. Unfortunately no, no change whatsoever. Any other ideas where the problem might be?
docsparks
(Docsparks)
February 10, 2021, 8:46pm
16
does you’re device need to have the new line character sent with the command? like it receives your json but isn’t receiving a “enter” character?
i totally understand the frustration in trying a million things and not wanting to show examples of what works and what didn’t, but when looking at your post of what works and what didn’t, i can only say from experience that the echo commands , shell commands and high quotation usage, you’re in for a doozy.
does your command work without the template code , but still with the /bin/bash stuff?
iway
(Chris)
February 10, 2021, 10:06pm
17
It works like this:
printf ‘{“command”:“SetParamList”,“messageID”:“1234”,“objectList”:[{“objnam”:“B1101”,“params”:{“LOTMP”:“86”}}]}’ | nc 192.168.xxx.xxx 6681
That successfully sets to 86 Farenheit.
docsparks
(Docsparks)
February 11, 2021, 8:49am
18
when i googled ‘echo vs printf’ it basically says taht echo defaults by adding a new line character at the end of the string.
another 5 hours wasted down the blackhole and im back at the /bin/bash part. if I knew more about the device you were sending to and the syntax it receives in, or had code to verify what works and could copy/paste the additional template into it myself, Im of no use.
Best of luck, would love to hear what works for you.