# How to turn on/off Raspberry Pi display? (permission errors)

**URL:** <https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861>\
**Category:** Scripts & Rules\
**Tags:** raspberry\
**Created:** [October 3, 2018, 10:41am UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861 "2018-10-03T10:41:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanMUC](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@StefanMUC](https://community.openhab.org/u/StefanMUC)\
**Post date:** [October 3, 2018, 10:41am UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/1 "2018-10-03T10:41:35Z")

</div>

Hey there,

as written in [HDMI Sleep - Raspberry Pi Forums](https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=47550) i used »hdmi\_blanking=1« in my `/boot/config.txt` to put my display connected to the Pi to standby after Pi booted up.  
After »apt-get upgrade« and updating from openHAB 2.2 to 2.3 this doesn’t work anymore.

- Platform information:
  - Hardware: Raspberry Pi 3 Model B
  - OS: openHABian
  - openHAB version: 2.3.0

So I thought: why not switch the display on/off through openHAB and be even more flexible. I have two scripts:  
`rpi-display-off.sh`

```
#!/bin/bash
tvservice -o

```

`rpi-display-on.sh`

```
#!/bin/bash
tvservice -p
fbset -depth 8
fbset -depth 16
chvt 7
sleep .1
chvt 1

```

They work quite well on console using `sudo` - but they don’t work with exec binding.

So I followed [OpenHAB sudo [Exec Binding]](https://community.openhab.org/t/openhab-sudo-exec-binding/34988) to give `openhab` user sudo rights:

> $ sudo -u openhab sudo -l  
> Matching Defaults entries for openhab on openHABianPi:  
> env\_reset, mail\_badpass, secure\_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
> 
> User openhab may run the following commands on openHABianPi:  
> (ALL) NOPASSWD: ALL

(I know “ALL” is not good for productive use, one should restrict to necessary commands)

But even with that, the scripts don’t work:

> $ sudo -u openhab ./rpi-display-off.sh  
> [E] Failed to initialize VCHI (ret=-1)

> $ sudo -u openhab ./rpi-display-on.sh  
> [E] Failed to initialize VCHI (ret=-1)  
> open /dev/fb0: Permission denied  
> open /dev/fb0: Permission denied  
> chvt: ioctl VT\_ACTIVATE: Operation not permitted  
> chvt: ioctl VT\_ACTIVATE: Operation not permitted

So how do I turn my display on/off using openHAB?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [October 3, 2018, 12:10pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/2 "2018-10-03T12:10:47Z")

</div>

Check the file with\> $ls -al /dev/fb0  
Is your user added to this group and does the file have the correct permissions?

---

<div class="post-metadata">

**Author:** ![StefanMUC](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@StefanMUC](https://community.openhab.org/u/StefanMUC)\
**Post date:** [October 3, 2018, 2:01pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/3 "2018-10-03T14:01:56Z")

</div>

Oh thanks, that looks good!

> $ ls -al /dev/fb0  
> crw-rw---- 1 root video 29, 0 Oct 3 12:10 /dev/fb0

So I added openhab to video group:

> $ sudo usermod -a -G video openhab

Now turning display on and off works (even without openhab in sudoers), but `rpi-display-on.sh` yields one last error:

> $ sudo -u openhab ./rpi-display-on.sh  
> Powering on HDMI with preferred settings  
> chvt: ioctl VT\_ACTIVATE: Operation not permitted  
> chvt: ioctl VT\_ACTIVATE: Operation not permitted

The `chvt` lines are needed in case of a double execute of the on script (otherwise screen is on but blank). What’s wrong here?

---

<div class="post-metadata">

**Author:** ![StefanMUC](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@StefanMUC](https://community.openhab.org/u/StefanMUC)\
**Post date:** [October 3, 2018, 2:06pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/4 "2018-10-03T14:06:32Z")

</div>

Oh still can’t call the scripts with openHAB:

> 2018-10-03 16:03:55.156 [INFO] [arthome.model.script.raspberry.rules] - Turning Raspberry display on  
> 2018-10-03 16:03:55.320 [INFO] [arthome.model.script.raspberry.rules] - [E] Failed to initialize VCHI (ret=-1)  
> open /dev/fb0: Permission denied  
> open /dev/fb0: Permission denied  
> chvt: ioctl VT\_ACTIVATE: Operation not permitted  
> chvt: ioctl VT\_ACTIVATE: Operation not permitted

What’s going wrong here? I can use `sudo -u openhab` to run the scripts successfully, but opneHAB itself gets permission denied? weird.

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [October 3, 2018, 2:35pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/5 "2018-10-03T14:35:07Z")

</div>

From the terminal what’s the output of $groups

Also check ls -al /etc/openhab2/scripts and make sure the scripts have correct permissions.

---

<div class="post-metadata">

**Author:** ![StefanMUC](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@StefanMUC](https://community.openhab.org/u/StefanMUC)\
**Post date:** [October 3, 2018, 8:28pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/6 "2018-10-03T20:28:15Z")

</div>

Those are correct, as I set them previously. Scripts get executed - otherwise I wouldn’t see the error messages!

> $ sudo -u openhab groups  
> openhab tty dialout audio video bluetooth gpio  
> $ ls -al |grep rpi  
> -rwxrwxr-x 1 openhab openhabian 25 Jul 12 22:51 rpi-display-off.sh  
> -rwxrwxr-x 1 openhab openhabian 80 Jul 12 23:16 rpi-display-on.sh

Only difference is that `sudo -u openhab` can execute the script properly, but openhab can’t do that - why?

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [October 3, 2018, 8:43pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/7 "2018-10-03T20:43:50Z")

</div>

> [@StefanMUC](#):
>
> but openhab can’t do that - why?

From where I’m sitting, can’t say for sure but shouldn’t openhabian be in sudo -u openhab groups.

---

<div class="post-metadata">

**Author:** ![StefanMUC](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@StefanMUC](https://community.openhab.org/u/StefanMUC)\
**Post date:** [October 3, 2018, 8:50pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/8 "2018-10-03T20:50:07Z")

</div>

Solved it… as unspectacular as it could be: Restart openHAB service and now it runs (with known `chvt` error message). Seems as group memberships aren’t automatically aplied to running processes

So if someone has a hint for `chvt` error message, I would be keen to try it.

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [October 3, 2018, 8:58pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/9 "2018-10-03T20:58:29Z")

</div>

Have you also used sudo systemctl daemon-reload since making your changes?

---

<div class="post-metadata">

**Author:** ![sjcliffe](https://community.openhab.org/user_avatar/community.openhab.org/sjcliffe/32/22262_2.png) [@sjcliffe](https://community.openhab.org/u/sjcliffe)\
**Post date:** [October 4, 2018, 4:20am UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/10 "2018-10-04T04:20:05Z")

</div>

I use:

```
vcgencmd display_power 1

```

to turn video display on and:

```
vcgencmd display_power 0

```

to turn if off. No sudo (root) required.

---

<div class="post-metadata">

**Author:** ![bassysta](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@bassysta](https://community.openhab.org/u/bassysta)\
**Post date:** [November 14, 2018, 11:50pm UTC](https://community.openhab.org/t/how-to-turn-on-off-raspberry-pi-display-permission-errors/52861/11 "2018-11-14T23:50:44Z")

</div>

Hi.  
I’ve tried your solution for the same problem, if i try:  
sudo -u openhab /script/monitorup.sh  
after added openhab to video group and rebooted raspberry, and the result is:

Powering on HDMI with preferred settings  
chvt: ioctl VT\_ACTIVATE: Operation not permitted

Screen power up but Blank. how have you soved it?
