Page 1 of 1
How to turn off/on hdmi.
Posted: Monday 31 July 2017 15:21
by capman
What I want is to turn off my kitchen screen when nobody is home or when we go to sleep.
I have found the command to do this. On putty a login to my raspberry pi 3 for my kitchenscreen (not domoticz) and
type 'vcgencmd display_power 0' to power the screen down and 'vcgencmd display_power 1' to get it back on. This is working.
Installed is latest raspbian jessie with pixel.When raspberry start up , automatic start chrome full screen with some frontpage for domoticz.(dashticz)
So in the script I want something like , if nobody is home OR if sleep = ON then 'vcgencmd display_power 0'.
I know how to ecexute a script with a dummy script in the command line from domoticz. But what kind of scripting should working best ?
LUA, Perl ,Python ? Domoticz running on my nas server so I must give the right adress from my kitchen screen to in the script.
Is there somebody who can help me to put me in the right direction ? Hope you understand my question.
Thanks.
Re: How to turn off/on hdmi.
Posted: Monday 31 July 2017 16:56
by mivo
Hi,
you need to execute some command or script remotely on RPi3 (Domoticz not running there, but on NAS), if I understand correctly.
Are you able to start SSH connection from NAS to RPi ? You can then start ssh connection with command as SSH argument. For example:
Code: Select all
$ ssh user@rpi-address /scripts/hdmi-off.sh
On RPi, in
/scripts/hdmi-off.sh you can then start
vcgencmd display_power 0 command or something. For unattended run, you should also create user, generate SSH keys and configure authentication. Not so difficult, but not easy
Another option is to check status of Virtual (Dummy) Domoticz switch on RPi side by some scripting. Shell script called from Cron for example, with some
curl ... and parsing should do it. You can do same for sure with another advanced scripting language (Python, LUA...)
Your choice ?

Re: How to turn off/on hdmi.
Posted: Monday 31 July 2017 17:16
by EddyG
Put a script in /etc/profile.d called savepower.sh an see to it that it is executable.
Take away the 2 '#' to turn off the leds too, if you want.
Or put "vcgencmd display_power 0" instead of the '/opt/vc/bin/tvservice -o'
Code: Select all
#!/bin/sh
# Turn OFF the LED's led0 = green and led1 = red
#sudo echo 0 | sudo tee /sys/class/leds/led0/brightness
#sudo echo 0 | sudo tee /sys/class/leds/led1/brightness
# Turn OFF HDMI
/opt/vc/bin/tvservice -o
Re: How to turn off/on hdmi.
Posted: Monday 31 July 2017 19:01
by capman
@mivo and @EddyG , first of all thanks 4 thinking about my 'problem'.
I have try the solution from EddyG and make a file called kitchscreen_off.sh and kitchenscreen_on.sh.
In both scripts I have this code:
Code: Select all
#!/bin/sh
# Turn OFF the LED's led0 = green and led1 = red
#sudo echo 0 | sudo tee /sys/class/leds/led0/brightness
#sudo echo 0 | sudo tee /sys/class/leds/led1/brightness
# Turn OFF HDMI
vcgencmd display_power 0
Exept for 'hdmi ON' I use '1'
So far so good this script is on the RPi of my kitchenscreen and it's executable 'sudo chmod -x filename.sh'.
But now, how can I execute this script when a switch is turning on or off , because my domoticz server is on my nas.
I can make a lua script in the script map from domoticz with device:
Code: Select all
commandArray = {}
if (devicechanged['MyDeviceName'] == 'On' then
'execute script on my kitchenscreen named 'kitchenscreen_on'
end
return commandArray
So what code can I use to execute.
Or maybe also a bash script with curl ? But I don't know how this works.
Pfff....

It's proberly simple but I have not enough coding skills.
Re: How to turn off/on hdmi.
Posted: Monday 31 July 2017 20:15
by capman
@mivo
I can start the ssh command in putty login from my nas server with command
ssh [email protected] /etc/profile.d/keukenscherm_off.sh
Then my screen goes off. How to use this command in a script ?
Re: How to turn off/on hdmi.
Posted: Monday 31 July 2017 21:33
by capman
OK, a little bit further now
I have found the execute command in lua , so it this now.
Code: Select all
commandArray = {}
if (devicechanged['test'] == 'On') then
os.execute ('ssh pi:@192.168.178.42 vcgencmd display_power 0')
end
return commandArray
This command is working terminal window from my nas , but after giving the password from my raspberry pi kitchen screen. It must be possible to give the password in the command itself. Something like this?
Or maybe with a ssh key ?
Give it up 4 this evening
O yes, this is my setup

, so 2 understand what I want 2 accomplish.
https://www.domoticz.com/forum/viewtopi ... 00#p134385
Re: How to turn off/on hdmi.
Posted: Tuesday 01 August 2017 8:09
by mivo
Hi,
great

scripts on RPi side works, LUA on Domoticz side will work probably after SSH keys config. Try these steps to setup SSH key auth:
http://www.linuxproblem.org/art_9.html
Re: How to turn off/on hdmi.
Posted: Tuesday 01 August 2017 20:21
by capman
This is working

, until I reboot my pi.

Then when a ssh from my nas 2 my pi it give the error '
Connection is closed
I have deleted the .ssh map on my nas , and give this command on my pi.
Code: Select all
sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server
Repeat the steps on the site you give , but no luck

I must properly delete all ssh keys and start over from scratch ,but how ?
Re: How to turn off/on hdmi.
Posted: Tuesday 01 August 2017 21:38
by capman
Working again from cli on my nas. Having delete the .ssh map on my pi also and start all over again.
Given from my terminal window on my nas set the screen off from my pi on the given ip adress.
Now 2 figure it out with the code on lua
Code: Select all
commandArray = {}
if (devicechanged['testje'] == 'On') then
os.execute ('ssh pi:@192.168.178.42 vcgencmd display_power 0')
end
return commandArray
That's still not working

Re: How to turn off/on hdmi.
Posted: Tuesday 01 August 2017 21:52
by cyberclwn
Hi,
try if this works for you:
or try:
Maybe your line works also, but without the ":" after pi in
Good luck.
Re: How to turn off/on hdmi.
Posted: Saturday 12 August 2017 0:00
by capman
Still no luck. Must try it with another scripting like bash or pyhton I think. Because lua can't handle os.execute with ssh so far.
Re: How to turn off/on hdmi.
Posted: Saturday 12 August 2017 14:14
by mivo
capman wrote: Saturday 12 August 2017 0:00
Still no luck. Must try it with another scripting like bash or pyhton I think. Because lua can't handle os.execute with ssh so far.
Hi,
try to catch command output and exit codes in LUA - try first with LS command. Anyway user@host in ssh command should be without colon:
Code: Select all
local cmd = 'ssh [email protected] ls -al'
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
local ex1, ex2, ex3 = f:close()
print('s: ' ..tostring(s))
print('ex1: ' ..tostring(ex1))
print('ex2: ' ..tostring(ex2))
print('ex3: ' ..tostring(ex3))
Re: How to turn off/on hdmi.
Posted: Saturday 12 August 2017 14:19
by SweetPants
Why not create a dummy switch and use "On/Off Action" bash script? You can control the switch from LUA
Re: How to turn off/on hdmi.
Posted: Saturday 12 August 2017 17:08
by capman
SweetPants wrote: Saturday 12 August 2017 14:19
Why not create a dummy switch and use "On/Off Action" bash script? You can control the switch from LUA
Yes I thought something 2 do like this , but what are the commands in the bash script ?
Re: How to turn off/on hdmi.
Posted: Saturday 12 August 2017 17:12
by SweetPants
Use the same scripts you used before to kill the screen