Turning on intergrated screen using command line in HA

I have a Raspberry pi4 with a intergrated touch screen monitor that has Home assistant installed via Venv on it.
I am using it as a control panel to control Home assistant, currently I have it to where it shuts off when not being used I prefer to have it keep doing that, I can remote in using putty to SSH and send these commands, export DISPLAY=:0 and xset dpms force on it turns on the display for a few mins just like I want, my question is how do I get Home assistant to do this via automation when it senses that I am home, I already have automation that turns on the lights and couple other things when I get home that part is done just need to add in the commands to turn on the monitor

I think you can use the Command line Switch.

ok and how do I write the command that does it?

First you have to check if the user that starts HA in the activated venv can run the command.
If that works, something like this should do it:

  - platform: command_line
        command_on: "export DISPLAY=:0; xset dpms force on"
        command_off: "export DISPLAY=:0; xset dpms force off"

ok thanks now I have a path to follow

Found this topic, maybe some help.

homeassistant@raspberrypi:~ $ xset dpms force on
No protocol specified
xset: unable to open display “:0”

ok I will try that config thanks

nope it straight up did not like that configuration

HA was okay with your original configuration but the last post on that link is exactly what I am doing

Hmm, google is full of those errors. Looks like the export DISPLAY=:0; xset dpms force on needs to run by the user that started the xserver.

That seems like a hack, but maybe try the example from the first post of the link.
Set up a ssh connection from the hass user to the user of the pi you’re using when the commands work.

The wake_on_lan integration shows an example how to setup a ssh session without password. (Points 1, 2, 4 and 5)
If the ssh works without a password, you can try the command_line switch from the link.

- platform: command_line
      command_on: ssh [email protected] 'export DISPLAY=:0 && xset dpms force on'
      command_off: ssh [email protected] 'export DISPLAY=:0 && xset dpms force off'
      command_state: ssh [email protected] 'export DISPLAY=:0 && xset -q | grep "Monitor is" | cut -c14-17' | grep "On" > /dev/null

Good luck!

Ok the commands on your last post do work under the Homeassistant user name on SSH, but does require a password to execute so now I am going to try to setup a account to do this without a password we will see what kind of train wreck this becomes LOL

nope the info on WOL did not work

okay for anybody that is wanting to have a monitor directly on the raspberry pi that homeassistant resides on
this needs to be done

  1. SSH into your Home assistant computer as normal
  2. install this first
  3. Change user to whatever your home assistant user name is “default is homeassistant” if default copy and paste
sudo apt-get install sshpass

sudo -u homeassistant -H -s

ssh [email protected] ‘export DISPLAY=:0 && xset dpms force on’

  1. Type yes.

  2. below command lines should now work for you in Home Assistant Switch Template

  - platform: command_line
        friendly_name: Touch Screen
        command_on:  sshpass -p YOUR_PASSWORD ssh [email protected] 'export DISPLAY=:0 && xset dpms force on'
        command_off:  sshpass -p YOUR_PASSWORD ssh [email protected] 'export DISPLAY=:0 && xset dpms force off'
        command_state:  sshpass -p YOUR_PASSWORD ssh [email protected] 'export DISPLAY=:0 && xset -q | grep "Monitor is" | cut -c14-17' | grep "On" > /dev/null