You might have suggestions to make this easier or better.
I created 2 dummy devices
- 1 percentage - idx 525 - Battery capacity (lading)
- 2 text - idx 516 - Battery status (charging, full, etc)
The python script:
Code: Select all
!/usr/bin/python
import sys
import ssl
import time
import datetime
import time
from urllib2 import urlopen
from time import sleep
# change these values
# domoticz = URL to the Domoticz server
# idx_ are the id's of the devices corresponding to the data in domoticz
domoticz = "http://192.168.188.61:8090"
idx_laptopaccustatus = 516
idx_laptopacculading = 525
# End
battery_status_file = "/sys/class/power_supply/BAT0/status"
battery_lading_file = "/sys/class/power_supply/BAT0/capacity"
def accustatuslaptop():
# time.sleep(0.1)
file = open(battery_status_file, "r")
return file.read()
def acculadinglaptop():
# time.sleep(0.1)
file = open(battery_lading_file, "r")
return file.read()
# EEEPC-Acculading
response= urlopen(domoticz+'/json.htm?type=command¶m=udevice&idx='+str(idx_laptopacculading)+'&nvalue=0&svalue='+str(acculadinglaptop()))
response.read()
# EEEPC-Accustatus
response= urlopen(domoticz+'/json.htm?type=command¶m=udevice&idx='+str(idx_laptopaccustatus)+'&nvalue=0&svalue='+str(accustatuslaptop()))
response.read()
Code: Select all
*/12 * * * * /home/bart/bin/batterycheck.py