Command line switch 'value_template' syntax

Hey. I’m a bit of a newbie to Home Assistant configuration.

I’m trying to set up a command line switch to control my receiver. My python scripts all work flawlessly when I run them from the command line. The only thing left is to get the “command_state” portion working…the documentation is making no sense to me. There is a script that queries the power state of the receiver, and it writes a result string to the console. Can I interpret this value in the value_template section (something other than 1 or 0…the values are different if I’m querying for the power state as opposed to the state of the mute button)? What’s the syntax for that?

Thanks!

I’m doing the following to ‘fix’ a commandline sensor output". it’s not a great example, but might help.

sensor:
  - platform: command_line
    name: bryant_occupancy
    command: python3 -c "import requests; print(requests.get('http://rpi0w:3000/status.json').json()['status'][0]['zones'][0]['zone'][0]['occupancy'][0])"
    value_template: '{% if value == "occupied" -%}on{%- else -%}off{%- endif %}'

It all depends what the output looks like. In my case of course is a json string.

Hrm…that doesn’t really help in my case. Here’s what I ultimately want to achieve:

Currently, I have a command line switch for which I have to write out shell commands in full. I also have these same shell commands in my shell_command section of config.yaml. Is it possible to have my switch use a shell_command entity instead of having to duplicate the command line?

I’ve since discovered that the query to determine state is not reliable, so I’m just going to leave it as a dumb switch, that runs the command for whatever I press.