usbrelay and simple commandline template

Begonnen von fabiobassa, 15 November 2019, 23:15:13

Vorheriges Thema - Nächstes Thema

fabiobassa

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

I am not a coder , I am much much better in hardware so please a little patience with me  ::)

amenomade

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"



Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

MadMax-FHEM

#2
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
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

amenomade

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...

Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

MadMax-FHEM

Hmm, ok.
So beeing in the sudoers group also avoids beeing asked for a password when using sudo!?

Thanks, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

amenomade

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 ;)
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus