-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_time_DomLcdBright.py
More file actions
36 lines (30 loc) · 1.18 KB
/
Copy pathscript_time_DomLcdBright.py
File metadata and controls
36 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import DomoticzEvents as DE
import subprocess as SUB
import urllib.request as URQ
sHead = "Python: TimeEvent: DomLcdBright: "
cmd = "cat /sys/class/backlight/rpi_backlight/brightness"
idx=DE.Devices["DomLcdBright"].id
curval=int(DE.Devices["DomLcdBright"].s_value)
baseurl = 'http://172.16.0.4:8080/json.htm?type=command¶m=udevice'
bSucces = True
try:
# NOTE: subprocess is run as root user by Domoticz
out = SUB.run(["rsh","root@172.16.0.251",cmd], stdout=SUB.PIPE, stderr=SUB.STDOUT, universal_newlines=True, timeout=10)
out.check_returncode()
except:
DE.Log(sHead + "Failed to retrieve brightness from remote screen!")
bSucces = False
if bSucces:
iBright = int(out.stdout)
fPerc = (iBright/255)*100
if fPerc > 0 and fPerc < 2:
iPerc=1
else:
iPerc=int(fPerc)
sUpdate = "No value change, no update"
if iPerc != curval:
url = baseurl + '&idx=' + str(idx) + '&nvalue=0&svalue=' + str(iPerc)
with URQ.urlopen(url) as f:
pass
sUpdate = "Fired URL: status " + str(f.status) + ", reason " + f.reason
DE.Log(sHead + "Read brightness: " + str(iBright) + ", Set brightPerc to:" + str(iPerc) + ", " + sUpdate)