Skip to content

Commit 21648af

Browse files
authored
Add better RPi power status reporting (#221)
1 parent 928a945 commit 21648af

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/rpi-cpu2mqtt.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,31 @@ def check_rpi_power_status():
106106
full_cmd = "vcgencmd get_throttled | cut -d= -f2"
107107
throttled = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
108108
throttled = throttled.decode('utf-8').strip()
109-
110-
if throttled == "0x0":
111-
return "OK"
112-
else:
113-
return "KO"
109+
throttled_val = int(throttled, 16)
110+
111+
if throttled_val & 1<<0:
112+
return "Under-voltage"
113+
if throttled_val & 1<<3:
114+
return "Soft temperature limit"
115+
if throttled_val & 1<<1:
116+
return "ARM frequency capped"
117+
if throttled_val & 1<<2:
118+
return "Throttled"
119+
120+
# These are "previous" statuses here for completeness
121+
# Home Assistant has the history so do not report them
122+
#
123+
#if throttled_val & 1<<16:
124+
# return "Previous under-voltage"
125+
#if throttled_val & 1<<17:
126+
# return "Previous ARM frequency cap"
127+
#if throttled_val & 1<<18:
128+
# return "Previous throttling"
129+
#if throttled_val & 1<<19:
130+
# return "Previous soft temperature limit"
131+
132+
return "OK"
133+
114134
except Exception as e:
115135
return "Error: " + str(e)
116136

0 commit comments

Comments
 (0)