Advertisement
Masoko

open-hardware-monitor-parser

Jul 20th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #!/usr/bin/python
  2. import json, urllib2
  3.  
  4. pc_ip = "192.168.0.100" # the ip of the pc where open hardware monitor is running http://openhardwaremonitor.org/
  5. pc_port = "8085" # the port on which OHM is running (default 8085) - you'll need to start the remote web server from OHM settings
  6. json_file = "data.json" #this is the name of the json file containing sensor data
  7.  
  8. response = urllib2.urlopen('http://'+pc_ip+':'+pc_port+'/'+json_file)
  9. data = json.load(response)  
  10.  
  11. cpu_temp = data['Children'][0]['Children'][1]['Children'][1]['Children'][4]['Value']
  12. cpu_load = data['Children'][0]['Children'][1]['Children'][2]['Children'][4]['Value']
  13.  
  14. gpu_temp = data['Children'][0]['Children'][2]['Children'][1]['Children'][0]['Value']
  15. gpu_load = data['Children'][0]['Children'][2]['Children'][2]['Children'][0]['Value']
  16.  
  17. print "CPU ",cpu_temp.split(' ')[0]+ " 'C ", cpu_load
  18. print "GPU ",gpu_temp.split(' ')[0]+ " 'C ", gpu_load
  19.  
  20. # Home Assistant configuration
  21. #
  22. #sensor main_cpu_temp:
  23. #  platform: command_line
  24. #  command: "/usr/bin/python /home/pi/py/pc-monitor/pccpu.py | cut -d ' ' -f 3"
  25. #  name: main pc cpu temp
  26. #  unit_of_measurement: "°C"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement