Turn off/on screen

Hi, I want to turn off and on the screen of my raspberry with an automation.
I find the code to do one sh file, how can I launch this file?
There is another method?
Thanks

To run shell commands and scripts: Shell Command - Home Assistant

Sorry for the noob question, I have only on command for turn off the screen.
I don’t understand if I had to make a sh file or i can insert this line on a home assistant script

Read through the docs I linked, make an attempt, post that attempt here if it doesn’t work.

Sorry but i’m new, i did this, but there are many things i wrong.
The first it’s i don’t know what i have to do on configuration.yaml, the second it’s how i can insert shell command on automation

alias: New Automation
description: 'Turn off screen at night'
mode: single
trigger:
  - platform: time
    at: '23:00'
condition: []
action:
  - service: shell_command.turn_off_screen
shell_command:
  turn_off_screen: sudo vcgencmd display_power 0

This should be in your configuration.yaml, not in the automation’s config.

If have HA running inside a docker container (as is the case with all installation types except for core), vcgencmd probably won’t be available inside the container.
You should be able to work around this issue by connecting to the host system using ssh. See this for information on how to set up ssh public key authentication for use with shell_command: SSH'ing from a command line sensor or shell command
You’ll also need to configure sudo to not ask for your password when running this command (vcgencmd display_power 0).

1 Like

Ah ok, now I have understood.
I did it this early morning and it work, the only one problem it’s that when I run the script I have a problem with the next.
I turn off the display with this command in script echo 1 > /sys/class/backlight/rpi_backlight/bl_power
Before any other commands I have to run this commands sudo chmod 777 /sys/class/backlight/rpi_backlight/bl_power.
Maybe there is a timing error on my automation, this evening I see better

It might be easier to do this instead of changing the permissions on the file:

echo 1 | sudo tee /sys/class/backlight/rpi_backlight/bl_power

Making the file world-writable could have unintended consequences (although in this case, it probably won’t).

1 hour ago I had a little time and I solve all.
It was one automation that doesn’t work, I don’t know why, but I did the automation from begin and all work good.
Now I have more improvement to do.
Thanks very much!