Schedule a command from Webcore to a raspberry pi after x hours of inactivity


#1

I am looking to turn of the monitor on my Retropie after a few hours of inactivity. I am running pi 4 with RetroPie and Hubitat with Webcore.

The command is simple: vcgencmd display_power 0, I have a motion sensor near the RetroPie just need to pull it together. So if I knew how to run that command with Webcore that would be a good option as well.


#2

Maybe an over the top solution for what you need…

I use nodered on my PI. There is a hubitat integration that allows HE devices to be monitored & controlled. So a simple nodered flow could be triggered by HE (possibly a virtual switch set for when you want it to run) then nodered could call a function to perform the command on the pi.

nodered is well worth a look, I have some very good temp & power monitoring graphs using reading taken from HE.


#3

I haven’t used node red. I can look into it but thought there might be a way to push command line commands via maker api or something to the pi


#4

I’ not too familiar with what would be involved, but suspect you’d need to write some target for the maker api to access.

There is a maker api to link to the nodered pallette. You probably already have nodered installed on the pi by default.

Another option is if you could create a web endpoint to perform the command for you, then WC could just perform a get request on the url. I’ve done this with a simple node.js app in the past, but find nodered easier to use & more flexible.


#5

What about this one…


#6

I tried flask a while back. I think I got stuck on the .pay file. Doesn’t cups in his example only control the printer?


#7

Yes, his cups example is for the printer but you can put the command you want to issue in a python executable file and that’s what you call from within flask.

I’m sure the retropi group would be able to give you the correct syntax for the script.


#8

They told me to come here lol. I know the command just not sure how to invoke it.

vcgencmd display_power 0

So would this be the correct code

from flask import Flask
import subprocess
app = Flask(name)

@app.route(’/’)

def my_command():
cmd = [“vcgencmd display_power 0”]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
out,err = p.communicate()
return out

if name == “main” :
app.run()


#9

the python popen docs may help you here. But for this example, you need to supply the command as a list of strings.

cmd = ["vcgencmd", "display_power", "0"]

#10

Thanks what should I use for the envir. Variable?