Autor Thema: usbrelay and simple commandline template  (Gelesen 520 mal)

Offline fabiobassa

  • Newbie
  • Beiträge: 1
usbrelay and simple commandline template
« am: 15 November 2019, 23:15:13 »
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  ::)

Offline amenomade

  • Hero Member
  • *****
  • Beiträge: 4812
Antw:usbrelay and simple commandline template
« Antwort #1 am: 16 November 2019, 01:39:54 »
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"


FHEM 5.9 Pi 3, EchoDot, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, und HM Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Offline MadMax-FHEM

  • Hero Member
  • *****
  • Beiträge: 6351
  • NIVEAu ist keine Creme...
Antw:usbrelay and simple commandline template
« Antwort #2 am: 16 November 2019, 09:43:46 »
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
« Letzte Änderung: 16 November 2019, 10:05:14 von MadMax-FHEM »
FHEM 5.9 PI3: HM-CFG-USB, 40x HM, ZWave-USB, 6x ZWave, EnOcean-PI, 3x EnOcean, HUE, CO2, ESP-Multisensor, FireTV, KODI, alexa-fhem, ...
FHEM 5.9 PI2: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, KODI, ha-bridge, ...
FHEM 5.9 PI3 (Test): HM-MOD-PCB, Snips, Google Home, ...

Offline amenomade

  • Hero Member
  • *****
  • Beiträge: 4812
Antw:usbrelay and simple commandline template
« Antwort #3 am: 16 November 2019, 11:32:37 »

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

FHEM 5.9 Pi 3, EchoDot, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, und HM Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Offline MadMax-FHEM

  • Hero Member
  • *****
  • Beiträge: 6351
  • NIVEAu ist keine Creme...
Antw:usbrelay and simple commandline template
« Antwort #4 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
FHEM 5.9 PI3: HM-CFG-USB, 40x HM, ZWave-USB, 6x ZWave, EnOcean-PI, 3x EnOcean, HUE, CO2, ESP-Multisensor, FireTV, KODI, alexa-fhem, ...
FHEM 5.9 PI2: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, KODI, ha-bridge, ...
FHEM 5.9 PI3 (Test): HM-MOD-PCB, Snips, Google Home, ...

Offline amenomade

  • Hero Member
  • *****
  • Beiträge: 4812
Antw:usbrelay and simple commandline template
« Antwort #5 am: 16 November 2019, 12:23:31 »
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 ;)
FHEM 5.9 Pi 3, EchoDot, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, und HM Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus