shortly upfront: thanks everyone for making this community one of the best and most supportive I seen on the web. Nearly all of my prior challenges got resolved by searching either the documentation or this forum.
My current challenge is to determine the state of a command line switch. I am querying my fhem instance to switch and determine the state of it using wget or curl. Switching works flawlessly but I can’t get the state evaluated properly. It would always resolve to false, no matter what.
- platform: command_line
feuerwerk:
command_on: /usr/bin/curl -X GET http://192.168.178.123:8086/fhem?cmd.Socket3=set%20Socket3%20on || true
command_off: /usr/bin/curl -X GET http://192.168.178.123:8086/fhem?cmd.Socket3=set%20Socket3%20off || true
command_state: /usr/bin/curl -X GET http://192.168.178.123:8086/fhem&cmd=%7BValue%28%22Socket3%22%29%7D&XHR=1
value_template: '{{ "on" == value }}'
I also tried "on" in value because of line breaks in the response or whatever, but no. The http response (I checked with wget, curl and in the browser) is “on” (w/o quotes) followed by a line break.
I tried to set the (global!) log level to debug to figure out what hass would receive as response, but it wouldn’t tell me. Before I go too much into detail, maybe someone already sees the mistake and can point me towards the solution?
Hi @atzbert
Maybe it’s not an elegant solution, but I use command_state this way:
it returns output when state should be on
it returns nothing when off
So try this
- platform: command_line
feuerwerk:
command_on: /usr/bin/curl -X GET http://192.168.178.123:8086/fhem?cmd.Socket3=set%20Socket3%20on || true
command_off: /usr/bin/curl -X GET http://192.168.178.123:8086/fhem?cmd.Socket3=set%20Socket3%20off || true
command_state: /usr/bin/curl -X GET http://192.168.178.123:8086/fhem&cmd=%7BValue%28%22Socket3%22%29%7D&XHR=1 | grep on | grep -v grep
@frkos
Thanks for your suggested solution. I actually tried it and even checked the cl return codes in the hass terminal, which would have to be 0 for on. And it is. It should work as well as the original solution, but it doesn’t.
The switch is always returning to the off state after two seconds.
I start feeling stupid and helpless. The sensor was a good idea because it gave me an error saying the response contains too many characters. tho on the terminal (even the one in hass) it would only show ‘on’ but if executed in the configurator “execute shell command” thingy it shows (presumably) the truth:
Command executed: /usr/bin/curl http://192.168.178.123:8086/fhem&cmd=%7BValue%28%22Socket3%22%29%7D&XHR=1: 0
on
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 3 100 3 0 0 103 0 --:--:-- --:--:-- --:--:-- 103
If I add a
| head -n 1
it would not execute because curl complains. I think I am missing here some basic shell knowledge…