i will edit a CommandLineSwitch to my HASS config.
My device looks like the following:

switch LEDBuero:
  platform: command_line
      friendly_name: LEDBuero
      command_on: "/usr/bin/curl --silent -X GET http://user:[email protected]/api/device/SteckdoseB2/turnOn | cut -c 3 | tr [r] 0"
      command_off: "/usr/bin/curl --silent -X GET http://user:[email protected]/api/device/SteckdoseB2/turnOff | cut -c 3 | tr [r] 1"
      value_template: '{{ return_value == "1" }}'
      command_state: "/usr/bin/curl --silent -X GET http://user:[email protected]/api/device/SteckdoseB2/getState | cut -d: -f2 |cut -d, -f1|tr [true] 0|cut -c 1"

The reason why it looks like this is:
i understood the Command Line Switch like this:

  • the on statement needs to get “0” as result from the curl command
  • the off statement needs to get “1” as result from the curl command
  • the get statement needs to get “0” for on
  • and if it’s not 0 the state is off so i also can be another sign… here it’s a “f” as result if the switch is not on…

But wat ever i’m doing the switch is alway flipping back to it’s “ground” position.
so he’s toggling.
He don’t stay’s in the position i switch him to…
(Hope i signed my problem good enough)

can somebody help me

thanks chris

the usually result of the curl On/Off - command without the pipes is this:

{“result”:true,“success”:true} --> off
{“result”:true,“success”:true} --> on
the get command gives this here:
{“result”:false,“success”:true} --> off
{“result”:true,“success”:true} --> on

command_on and command_off don’t seem to care about return codes.

command_state expects a return value of 0 to indicate it is on.

If your script DOES NOT return a return code of 0 THEN you need to add the value_template to parse what the ON value is.

Ok it’s returning “0” for on.
So it’s working.
how has now the “command_state” to look like?

it’s the
"/usr/bin/curl --silent -X GET http://user:[email protected]/api/device/SteckdoseB2/getState | cut -d: -f2 |cut -d, -f1|tr [true] 0|cut -c 1"
It’s resulting “0” for on and “f” for not on

Mit freundlichen Grüßen

Can’t some one help?!

Can’t somebody help …?

I have been away for a few days, I really don’t understand the question there isn’t much to these command line switches and the examples are fairly clear.

If you have altered your command_state: to directly return 0 for on then just remove value_template: ?

The switches work.
But I have underlying another software.
I want HASS to recognize which state the switches have.
So I need the “GetState” command.

I too am looking for what the purpose and how command_state works.

It’s mentioned in the documentation, but it doesn’t say what it does or how it works.

Did you ever figure this out?

No I finished the HASS-Theme for me.

It doesn’t have the features I would like to use…