[QUESTION] Run a system command
seppelicous opened this issue ยท 7 comments
Plugin Version
0.5.0
Question
I can use "kasa --host 192.168.178.27 on" as a pi user to switch my Kara socket on. Using this as a system command in your plugin does not seem to work. Am doing it right? "sudo" did not help either.
Can I use any command that I use in terminal?
You should be able to use any command you can use in the terminal. Could you attach your octoprint.log
? There should be an error message if something went wrong.
Good idea with the log...
2022-04-08 11:26:26,473 - octoprint.plugins.physicalbutton - DEBUG - Reacting to button Steckdose - 8
2022-04-08 11:26:26,474 - octoprint.plugins.physicalbutton - DEBUG - Sending activity with identifier 'kasa --host 192.168.178.27 on' ...
2022-04-08 11:26:26,474 - octoprint.plugins.physicalbutton - INFO - Executing system command 'kasa --host 192.168.178.27 on'
2022-04-08 11:26:26,534 - octoprint.plugins.physicalbutton - ERROR - Error [127] executing command 'kasa --host 192.168.178.27 on': /bin/sh: 1: kasa: not found
2022-04-08 11:26:26,535 - octoprint.plugins.physicalbutton - ERROR - The activity with identifier 'kasa --host 192.168.178.27 on' failed! Aborting follwing activities!
I wonder why it cannot execute "kasa" as works flawlessly in terminal, also with user "pi" without "sudo".
I did a bit of research and it seems like the module I'm using is not using the bash shell but the sh shell. I'll have to inform myself on how to change that. Maybe that could resolve your issue.
Could you reinstall the plugin with this link
https://github.com/LuxuSam/PhysicalButton/archive/refs/heads/bug-bash-shell.zip
to try it out? I added a parameter which forces a bash shell :)
If you do not know how to install it with a link do as following:
- Open Settings
- Go to Plugin Manager
- Click +Get More
- Paste the link under ... from URL
- Hit Install next to that text field
Unfortunately it still throws an error, as also "bash" seems not to work.
octoprint.plugins.physicalbutton - ERROR - Error [127] executing command 'kasa --host 192.168.178.27 on': /bin/bash: kasa: command not found
I wish I could help, but I have little to no experience with this.
Nevertheless I found a possible workaround with MQTT messages, which might be an interesting feature for this plugin too.
The buttons send individual messages to an mqtt broker and the action is processed in NodeRed.
To test it out I also installed python-kasa
, with ~/oprint/bin/pip install python-kasa
.
I am able to run the command with /home/pi/oprint/bin/kasa --host 'local ip address' on
from a button ๐
So you'll probably also have to specify the absolute path to the command.
Great, thank you very much for the investigation. It works for after reinstall with ~/oprint/bin/pip install python-kasa
. I am not sure where it was installed initially.
Works great for me!