Command line switch for kodi

Hi. I am trying to create a switch for kodi. The sensor works. i get readings. but the switch doesnt. I dont even get the switch entity created. This is the code.

sensor:
  - platform: command_line
    command: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power'
    name: Kodi Sleep Status
switch:
  - platform: command_line
    switches:
      kodi_power:
        command_on: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power 1'"
        command_off: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power 0'"
        command_state: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power'"
        value_template: "{{ states('sensor.kodi_sleep_status') == 'display_power 1' }} "
        friendly_name: Kodi Power State

What am i doing wrong

Hey Anand,

I don’t have experiences with the command_line sensor/switch, however I’d put the command of your sensor in double quotes as well.
Restart Home Assistant and have a look into your log - does anything show up?
Is the switch in the Developer Tools - States?

Hi. The sensor works fine. I get the entity in developer tools and the status is showing correctly.

Its the switch that isnt working. No switch entity at all. Logs doesnt show any error. No entry for the command line switch / sensor

Alright then, I’d still put quotes on the sensor command to make sure it doesn’t interferr with the following yaml.

What happens when you comment out (put a # in front of) command_state and value_template?

EDIT: Maybe it’s the YAML, try out the comments.

Thanks for the reply. Will test out your suggestions as soon as i get back

putting the command of sensor in quotes changes nothing.

commenting out command_state and value_template does nothing too.

tried commenting out the sensor. just removes the sensor as expected. still no switch.

Hm, that’s weird. I’d try to set the loglevel to debug:
In configuration.yaml:

logger:
  default: critical
  homeassistant.components.command_line: debug

This increases the verbosity of the command_line log. If there’s nothing relevant showing up, try:

logger:
  default: debug

Will spit out a lot. However it might help in your case :thinking:

hi. found the problem. i had 2 switch in my yaml. so it was ignoring the first call. Now that’s solved.

I got another problem. the sensor updates every 60 seconds (default). when i toggle the switch, the status does not reflect the actual state.

  - platform: command_line
    switches:
      kodi_power:
        command_on: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power 1'"
        command_off: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power 0'"
        command_state: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power'"
        value_template: " {{ states('sensor.kodi_sleep_status') == 'display_power=1' }} "
        friendly_name: Kodi Power State

I think the problem is due to the value template. Is there a way to use the ssh command in the value template as opposed to the sensor state?

Nice!

Try this for your value_template:

value_template: " {{ value == 'display_power=1' }} "
1 Like

wow. that worked. how stupid of me. thanks alot.

1 Like

Not stupid, it could be more clear that “value” is the variable that gets generated from the state command, but I’m glad it works now :slight_smile:

1 Like