Hello,
Does anybody know how to execute a script (.py) from the local folder (www)?
Script test.py is saved in: /home/homeassistant/.homeassistant/www
URL: http://MY_HA_SERVER:8123/local/test.py
It is working fine for html pages but I would like to execute a .py file? Is it possible?
Thanks!
I don’t know if I really understood what you want to do, but I think what you are looking for is a way to run a python script from a php file via the browser.
This definitely requires some privilege settings. Apache web server runs any script as user www-data and thus www-data needs to have access to your test.py .
As your python file is outside of the web servers directory (which is a good thing, in fact) www-data would need to be able to run the script as sudo. So you need to edit the /etc/sudoers file.
Change to /etc and run sudo visudo(DO NOT attempt to edit the file otherwise, typing errors might cause trouble and sudo visudowill check the syntax before saving.
You might edit the sudoers file as follows, i.e. adding those lines:
I know how to do it with PHP but I have no idea what is the web server used in Home Assistant.
What is the web server behind HA? Does it accept cgi-bin or something similar to execute Python scripts?