Command Line Switch help

Hi there,
i have a problem by setting up my command line switches. HA doesnt show them. Theres no error message at all. The command line sensors work fine.

Can you post the code here using code blocks (</>)?

I copied this code

 - platform: command_line
switches:
 #Switch for Foscam Motion Detection
  foscam_motion_livingroom:
    command_on: "python3 /path/to/foscam.py 'setMotionStatus' '192.168.2.50' 'username' 'password' '1'"
    command_off: "python3 /path/to/foscam.py 'setMotionStatus' '192.168.2.50' 'username' 'password' '0'"
    command_state: "python3 /path/to/foscam.py 'getMotionStatus' '192.168.2.50' 'username' 'password'"
    value_template: '{{ value == "1" }}'
    friendly_name: Living Room Detection Status

I changed user and password. When i run the command from the terminal it works, but HA doesnt create the switch

I would try it like this…

- platform: command_line
  switches:
   #Switch for Foscam Motion Detection
    foscam_motion_livingroom:
      command_on: python3 "/path/to/foscam.py 'setMotionStatus' '192.168.2.50' 'username' 'password' '1'"
      command_off: python3 "/path/to/foscam.py 'setMotionStatus' '192.168.2.50' 'username' 'password' '0'"
      command_state: python3 "/path/to/foscam.py 'getMotionStatus' '192.168.2.50' 'username' 'password'"
      value_template: '{{ value == "1" }}'
      friendly_name: Living Room Detection Status

You may need to specify the path to python3 as well.

Yes, i’ve done this.
when i enter the command in the terminal, it works.
The problem is that the switch is not displayed in home assistant. i even get no error in the log.
nothing happens.

Thats my switch.yaml

  - platform: tplink
    host: 192.168.0.5
    name: WZ_Beamer
  - platform: tplink
    host: 192.168.0.38
    name: AR_Buegelstation
  - platform: mqtt
    command_topic: "cmnd/BU_Computeranlage/POWER"
    state_topic: "stat/BU_Computeranlage/POWER"
    name: "BU_Computeranlage"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true
    qos: 1
  - platform: mqtt
    command_topic: "cmnd/WZ_Entertainmentcenter/POWER"
    state_topic: "stat/WZ_Entertainmentcenter/POWER"
    name: "WZ_Entertainmentcenter"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true
    qos: 1
  - platform: mqtt
    command_topic: "cmnd/WZ_Getraenkekuehlschrank/POWER"
    state_topic: "stat/WZ_Getraenkekuehlschrank/POWER"
    name: "WZ_Getraenkekuehlschrank"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true
  - platform: mqtt
    command_topic: "cmnd/WZ_StatusKuehlschrank/POWER"
    state_topic: "stat/WZ_StatusKuehlschrank/POWER"
    name: "WZ_KuehlschrankMainSwitch"
    payload_on: "ON"
    payload_off: "OFF"
    qos: 1
    optimistic: false
    retain: true
  - platform: mqtt
    command_topic: "cmnd/WZ_Zapfanlage/POWER"
    state_topic: "stat/WZ_Zapfanlage/POWER"
    name: "WZ_Zapfanlage"
    payload_on: "ON"
    payload_off: "OFF"
    qos: 1
    optimistic: false
    retain: true
  - platform: mqtt
    command_topic: "cmnd/FL_BewaesserungBlume1/POWER"
    state_topic: "stat/FL_BewaesserungBlume1/POWER"
    name: "FL_BewaesserungBlume1"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 1
    retain: true
  - platform: mqtt
    command_topic: "cmnd/BU_Drucker/POWER"
    state_topic: "stat/BU_Drucker/POWER"
    name: "BU_Drucker"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true
  - platform: mqtt
    command_topic: "cmnd/AR_Trockner/POWER"
    state_topic: "stat/AR_Trockner/POWER"
    name: "AR_Trockner"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true
  - platform: command_line
    switches:
     #Switch for Foscam Motion Detection
      bu_motion_switch:
        command_on: "python3 /home/andyx87/homeassistant/bin/foscam.py 'setMotionStatus' '192.168.0.74' 'XXX' 'XXX' '1'"
        command_off: "python3 /home/andyx87/homeassistant/bin/foscam.py 'setMotionStatus' '192.168.0.74' 'XXX' 'XXX' '0'"
        command_state: "python3 /home/andyx87/homeassistant/bin/foscam.py 'getMotionStatus' '192.168.0.74' 'XXX' 'XXX'"
        value_template: '{{ value == "1" }}'
        friendly_name: Living Room Detection Status

I just copied your code into my switches.yaml and added it to my livingroom group and …

image

So there is nothing wrong with the switch definition, so either you haven’t added it to a group or it’s appearing in the group all switches.

The Switch is definitely not listet in my dev-states

Is there any package I need to install first?
I tried it on a virgin installation of ha too. But nothing.

Ps
I have no problems with the command line sensors. The work fine

Ha runs in a virtual environment. But I testet the code also in the vi and it worked.

How are you loading the switches?

What do you mean with loading switches?

You have a line like switch: !include switch.yaml in your config.yaml file?

Yes
All other switches in the config are running fine

Try moving the command line switch to the top of the switch.yaml file.

Did not help.
I found this here in the log

RPCFunctions.addDeviceNames: Could not access XML-API: HTTP Error 404: Not Found

I found my bug.
I loaded the config.yaml from a backup. In this backup was the link to the switch.yaml not set.

Thanks a lot for helping!