Trying to add a command_line py to Switches

I have 4 TP link switches that work fine.
Im trying to add a a switch that works via a python file. I work 100% from putty but I cant get it to appear in the Home Assistant.

This is what I have done so far… TP links work fine but nothing appears for the command line entry.
I do get a invalid config error for switch,command-line.

switch:

  • platform: tplink
    host: 192.168.0.xx
  • platform: tplink
    host: 192.168.0.xx
  • platform: tplink
    host: 192.168.0.xx
  • platform: tplink
    host: 192.168.0.xx
  • platform: command_line
    switches:
    kitchen_light:
    command_on: python /usr/local/lib/python2.7/dist-packages/energenie/ENERG002-SW4_ON.py
    command_off: python /usr/local/lib/python2.7/dist-packages/energenie/ENERG002-SW4_OFF.py

BTW - Home Assistant rocks…

Hi All.

Ive been at this all weekend and cant sort it.

Id appreciate any help that I get.

Im trying to add command line py scripts to my TP link switches in Home Assistant

I even tried a new configuration.yaml with just the command line stuff in it and that gives an error too…

Please anyone ?

Here’s an example of one of my command line switches that works:

switch:
  platform: command_line
  switches:
    zap1_shell_pilight:
      command_on: 'pilight-send -p clarus_switch -t -u=60 -i=A4'
      command_off: 'pilight-send -p clarus_switch -f -u=60 -i=A4'

Can you provide a copy of the error you receive, plus paste your code using the </> tag so we can see the correct formatting?

1 Like

I’ve got a couple of DLink switches and they work like this:

# DLINK switches
#
  - platform: dlink
    name: Dlink1
    host: 192.168.0.xx
    username: xxxxxxx
    password: xxxxxxx
  - platform: dlink
    name: Dlink2
    host: 192.168.0.xx
    username: xxxxxxx
    password: xxxxxxx

And then they just show up as normal switch no extra lines of code needed for on/off.

Hope it works for you this way too.

Here is my configuration.yaml with my details XXX out.
I havent added in the code above but I want to be able to have a switch (in the same place as my TPlink switches) that run these 2 py scripts.

/usr/local/lib/python2.7/dist-packages/energenie/energ002-sw4_on.py
/usr/local/lib/python2.7/dist-packages/energenie/energ002-sw4_off.py

I tried to change the text @jeremyowens you provided but I kept locking up the home assisitant and had to edit yaml and reboot PI to get it back.

If someone knows and can edit my text that would be a big help…

@jayjay Im using an addon thats attached to the Pi and using RF and scripts is the only thing that works for it. (Energenie PiMote).

[code]
homeassistant:

Name of the location where Home Assistant is running

name: Home

Location required to calculate the time the sun rises and sets

latitude: xxxxxxxx
longitude: xxxxxxxx

Impacts weather/sunrise data (altitude above sea level in meters)

elevation: xxxxxxxx

metric for Metric, imperial for Imperial

unit_system: metric

Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

time_zone: xxxxxxxx

Show links to resources in log and frontend

introduction:

Enables the frontend

frontend:

Enables configuration UI

config:

http:

Uncomment this to add a password (recommended!)

api_password: PASSWORD

Uncomment this if you are using SSL or running in Docker etc

base_url: example.duckdns.org:8123

Checks for available updates

updater:

Discover some devices automatically

discovery:

Allows you to issue voice commands from the frontend in enabled browsers

conversation:

Enables support for tracking state changes over time.

history:

View all events in a logbook

logbook:

Track the sun

sun:

Weather Prediction

sensor:
platform: yr

Text to speech

tts:
platform: google

device_tracker:

  • platform: xxxxxxxx
    host: xxxxxxxx
    username: xxxxxxxx
    password: xxxxxxxx
    interval_seconds: 10
    consider_home: 180
    track_new_devices: no

switch:

  • platform: tplink
    host: 192.168.0.xx
  • platform: tplink
    host: 192.168.0.xx
  • platform: tplink
    host: 192.168.0.xx
  • platform: tplink
    host: 192.168.0.xx
    [/CODE)

Here is my configuration.yaml with my details XXX out.I havent added in the code above but I want to be able to have a switch (in the same place as my TPlink switches) that run these 2 py scripts.

/usr/local/lib/python2.7/dist-packages/energenie/energ002-sw4_on.py
/usr/local/lib/python2.7/dist-packages/energenie/energ002-sw4_off.py

I tried to change the text @jeremyowens you provided but I kept locking up the home assisitant and had to edit yaml and reboot PI to get it back.

If someone knows and can edit my text that would be a big help…

@jayjay Im using an addon thats attached to the Pi and using RF and scripts is the only thing that works for it. (Energenie PiMote).

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: xxx
  longitude: xxx
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 2
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: xxx

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

http:
  # Uncomment this to add a password (recommended!)
  # api_password: PASSWORD
  # Uncomment this if you are using SSL or running in Docker etc
  # base_url: example.duckdns.org:8123

# Checks for available updates
updater:

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

# Track the sun
# sun:

# Weather Prediction
sensor:
  platform: yr

# Text to speech
tts:
  platform: google

device_tracker:
  - platform: xxx
    host: 192.168.xxx
    username: xxx
    password: xxx
    interval_seconds: 10
    consider_home: 180
    track_new_devices: no
    
switch:
  - platform: tplink
    host: 192.168.0.xxx
  - platform: tplink
    host: 192.168.0.xxx
  - platform: tplink
    host: 192.168.0.xxx
  - platform: tplink
    host: 192.168.0.xxx

Just out of curiosity, can you place the .py scripts in a directory that you know your HASS user has access to? Like maybe create a scripts directory in your HASS root folder and place the scripts there? I am wondering, if for some reason, if your HASS user cannot access the scripts path?

This is my python command line switch, note the ’ which yours doesn’t have.

  lockaction:
    command_on: 'python3 /Users/homeassistant/.homeassistant/mp3/lockon.py'
    command_off: 'python3 /Users/homeassistant/.homeassistant/mp3/lockoff.py'