added sensor reading utility

master
BodgeMaster 2021-05-01 06:51:35 +02:00
parent 856392749c
commit 87d9131ccf
1 changed files with 20 additions and 0 deletions

20
sensors.py Normal file
View File

@ -0,0 +1,20 @@
import os, json, sys
try:
sensor_group = sys.argv[1]
sensor = sys.argv[2]
except IndexError:
print("usage: python3 "+sys.argv[0]+" <sensor group> <sensor>")
sys.exit(1)
sensors_process = os.popen("sensors -j")
temps_str = sensors_process.read()
sensors_process.close()
temps = json.loads(temps_str)
try:
print([value for key, value in temps[sensor_group][sensor].items() if key.endswith("input")][0])
except KeyError:
print("Sensor \""+sensor_group+":"+sensor+" not found!")
sys.exit(1)