Help how to run python script noob

Hi there

i’m trying to run a python script to turn on my projector https://github.com/R3MRUM/sonyp_rs232c
now i can run the script (toggle_power.py) by going to the directory /sonyp_rs232c/test/ then typing “python3 toggle_power.py” in the terminal turns on my projector with no problem…

now i have tried to follow other peoples configuration.yaml files

but mine dose’nt seem to work is there something i’m missing??

switch:

  • platform: command_line
    switches:
    sonyp_rs232c:
    command_on: “python3 /home/homeassistant/.homeassistant/python_scripts/sonyp_rs232c/toggle_power.py”
    command_off: “python3 /home/homeassistant/.homeassistant/python_scripts/sonyp_rs232c/toggle_power.py”
    friendly_name: Projector

Can you format your code so it looks like it’s supposed to?

I have no idea how to do that im a noob :grimacing:

Python_scripts are not used in that way.

I take it somewhere in your configuration you have

python_script:

?

If so, in your service panel, in the drop down list you should see the python_script(s), something like…

Then if you want a ‘button’ on your front end, you can add a script to your configuration:

script:
  python_toggle_power:
    alias: Toggle Projector
    sequence:
      - service: python_script.toggle_power

Then when you press ACTIVATE on the front end, your python script will run.

Hope this helps.

2 Likes

Hi so i what i did at first was made a folder in my .homeassistant/ directory called “python_script” and i put the folder “sonyp_rs232c” in there
So thats what i thought but guess i was wrong

The directory needs to be called python_scripts (with an S on the end).

See the big blue box at the top of the page?

To MF_social
I changed the directory to python_scripts…

So do I just put this in the configuration. Yaml