Good evening all on this forum, I am writing from south italy and new to fhem
Ask pardon if this argument has already be discussed. may be in other language but is possible to create a simple template of 2 buttons and on click pass a cli command , for example
sudo ./usbrelay PSUIS_2=1
to set on
sudo ./usbrelay PSUIS_2=0
to set off
I am referring to this project
https://github.com/darrylb123/usbrelay (https://github.com/darrylb123/usbrelay)
I am not a coder , I am much much better in hardware so please a little patience with me ::)
See here: https://fhem.de/commandref.html#command
You can pass shell commands with "sudo ./usbrelay PSUIS_2=1"
or
qx(sudo ./usbrelay PSUIS_2=1)
(to sudo, the fhem user must be in the sudoers group
You can define some dummy in Fhem, and set an attribute "setList" on them. Then react on these dummies with "notify" or "DOIF"
See corresponding modules (dummy, notify, DOIF) in CommandRef
For example something like:
define ntrelay notify dummyRelay:on "sudo ./usbrelay PSUIS_2=1"
Just one additional remark:
when sudo is really necessary then additionally of beeing in the sudo group (really necessary? cannot remember to put User fhem into it) you have to "specify" for User fhem not needing a password at least when using your script (./usbrelay)!
Make a copy of the file for User pi (assuming you installed on a Raspberry PI with "actual" OS [stretch/buster]) found in /etc/sudoers.d/ and adopt for user fhem...
And better use the full path instead of "just" ./usbrelay !
Because that depends on "where you are" the moment "you" issue the command...
EDIT: and of course better use visudo to edit the new file! visudo -f FILENAME
And maybe place the script somewhere in /opt/fhem because that is the "home directory" of the User fhem...
So the User fhem should have no issue accessing it...
(also check "user rights" the file should "belong" to fhem:dialout on a standard fhem installation / could be "changed" via sudo chown fhem:dialout FILE-NAME-AND-PATH )
EDIT: if you want to test if the script works with user fhem you can do the following on the console (as user pi): sudo -su fhem bash
and then you "are" User fhem on the console and can test. The same would work (as from amenomade suggested) to "just" put the command in the "FhemWeb line" using quotation marks around...
Regards, Joachim
Zitat von: MadMax-FHEM am 16 November 2019, 09:43:46
when sudo is really necessary then additionally of beeing in the sudo group (really necessary? cannot remember to put User fhem into it) you have to "specify" for User fhem not needing a password at least when using your script (./usbrelay)!
All roads lead to Rome ;)
In the sudoers group, or specifically mentioned in sudoers file or...
Perhaps you'll also need the user fhem to have a shell
If "not needing a password", then better restrict the possible commands, otherwise the fhem interface will be able to issue any system command...
Hmm, ok.
So beeing in the sudoers group also avoids beeing asked for a password when using sudo!?
Thanks, Joachim
Zitat von: MadMax-FHEM am 16 November 2019, 12:13:37
Hmm, ok.
So beeing in the sudoers group also avoids beeing asked for a password when using sudo!?
Thanks, Joachim
Depending on what the sudoers group is allowed to do in the sudoers file ;)