ironsheep / RPi-Reporter-MQTT2HA-Daemon

Linux service to collect and transfer Raspberry Pi data via MQTT to Home Assistant (for RPi Monitoring)
GNU General Public License v3.0
441 stars 62 forks source link

Custom commands, error vcgencmd "not allowed" #150

Open arnocl opened 1 month ago

arnocl commented 1 month ago

Checklist:

Release with the issue: 1.8.5

Hardware, Operating System, Python version: RPi 4 Model B r1.4, bullseye 6.1.21-v8+

Description of problem: I want to run a command from Home Assistant to turn of my 2 screens, plugged in directly to my Pi4. I am able to turn these off and back on again from the terminal with the following commands:

on:
vcgencmd display_power 1 7
vcgencmd display_power 1 2

off:
vcgencmd display_power 0 7
vcgencmd display_power 0 2

I tried to implement these functions by creating new commands in the config file:

screen_right_on = /usr/bin/sudo vcgencmd display_power 1 2
screen_right_off = /usr/bin/sudo vcgencmd display_power 0 2
screen_left_on = /usr/bin/sudo vcgencmd display_power 1 7
screen_left_off = /usr/bin/sudo vcgencmd display_power 0 7

In the sudoers file I registered the display_power command: daemon smartmirror =NOPASSWD: /usr/bin/systemctl restart isp-rpi-reporter.service,/sbin/shutdown,/usr/bin/vcgencmd display_power>

When I try to run these commands from Home Assistant I see an entry in the auth-log file, but it is generating an error: smartmirror sudo: daemon : command not allowed ; PWD=/opt/RPi-Reporter-MQTT2HA-Daemon ; USER=root ; COMMAND=/usr/bin/vcgencmd display_power 0 7

In the log it states that /opt/vc/bin/vcgencmd can't be accessed, it doesn't exist. Is this related to my problem?

What can be done to enable the service to run these commands?

Run our report script 'genBugInfo' on your failing device and include the output here:

# SCRIPT genBugInfo v1.1 run 24/05/13-16:43:12
# ----------------------------------------------------------------------

# /bin/cat /etc/apt/sources.list | /bin/egrep -v '#'

deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi

 ----

# /bin/cat /etc/apt/sources.list | /bin/egrep -v '#' | /usr/bin/awk '{ print $3 }' | /bin/grep . | /usr/bin/sort -u | head -1

bullseye

 ----

# /bin/uname -r

6.1.21-v8+

 ----

# /bin/hostname -f

smartmirror

 ----

# /usr/bin/uptime

 16:43:12 up  1:10,  2 users,  load average: 0,36, 0,22, 0,18

 ----

# /sbin/ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.212  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::5881:3336:5d8f:1dca  prefixlen 64  scopeid 0x20<link>
        ether e4:5f:01:0e:44:6b  txqueuelen 1000  (Ethernet)
        RX packets 119306  bytes 48951503 (46.6 MiB)
        RX errors 0  dropped 213  overruns 0  frame 0
        TX packets 85225  bytes 20702267 (19.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 368  bytes 20706 (20.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 368  bytes 20706 (20.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 ----

# /sbin/ifconfig | /bin/egrep 'Link|flags|inet|ether' | /bin/egrep -v -i 'lo:|loopback|inet6|\:\:1|127\.0\.0\.1'

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.212  netmask 255.255.255.0  broadcast 192.168.1.255
        ether e4:5f:01:0e:44:6b  txqueuelen 1000  (Ethernet)

 ----

# /sbin/route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    202    0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0

 ----

# /bin/ls -l /var/log/dpkg.log /var/log/dpkg.log.1 2>/dev/null

-rw-r--r-- 1 root root      0  8 mei 06:26 /var/log/dpkg.log
-rw-r--r-- 1 root root 141421  7 mei 21:26 /var/log/dpkg.log.1

 ----

# /bin/grep 'status installed' /var/log/dpkg.log /var/log/dpkg.log.1 2>/dev/null | sort | tail -1

/var/log/dpkg.log.1:2024-05-07 21:26:59 status installed unclutter-startup:all 8-25

 ----

# /bin/df -m

Bestandssysteem 1M-blokken Gebruikt Beschikbaar Geb% Aangekoppeld op
/dev/root            29631     4915       23458  18% /
devtmpfs              3649        0        3649   0% /dev
tmpfs                 3907       31        3876   1% /dev/shm
tmpfs                 1563        2        1562   1% /run
tmpfs                    5        1           5   1% /run/lock
/dev/mmcblk0p1         255       51         205  20% /boot
tmpfs                  782        1         782   1% /run/user/1000

 ----

# /bin/df -m | /usr/bin/tail -n +2 | /bin/egrep -v 'tmpfs|boot'

/dev/root            29631     4915       23458  18% /

 ----

# ls -l /opt/vc/bin/vcgencmd /usr/bin/vcgencmd

ls: kan geen toegang krijgen tot '/opt/vc/bin/vcgencmd': Bestand of map bestaat niet
-rwxr-xr-x 1 root root 13948 22 mrt  2023 /usr/bin/vcgencmd

 ----
arnocl commented 1 month ago

Managed to get the same result with the command line integration in HA. Used the guide found here: SSH’ing from a command line sensor or shell command

It would be nice if the same could be done through this script.