add option to show power units

This commit is contained in:
M.J. Wydra
2020-12-05 16:18:42 -06:00
parent 43c23b7af9
commit 6472dc534f
3 changed files with 31 additions and 7 deletions

View File

@@ -10,7 +10,8 @@ MQTT_PASSWORD = os.getenv('MQTT_PASSWORD')
MQTT_QOS = int(os.getenv('MQTT_QOS', 1))
MQTT_TOPIC = os.getenv('MQTT_TOPIC', 'server')
INTERVAL = int(os.getenv('INTERVAL', 60))
MONITORED_CONDITIONS = os.environ.get('MONITORED_CONDITIONS','alarm,capacity,capacity_level,present,status,voltage_now')
MONITORED_CONDITIONS = os.environ.get('MONITORED_CONDITIONS','status,capacity,energy_now,energy_full,energy_full_design,power_now,voltage_now')
SHOW_UNITS = os.getenv('SHOW_UNITS', 1)
BATTERY_HEALTH = os.getenv('BATTERY_HEALTH', 1)
TIME_REMAINING = os.getenv('TIME_REMAINING', 1)
@@ -35,7 +36,17 @@ while True:
if name in ['alarm', 'capacity', 'cycle_count', 'online', 'present']:
payload[name] = int(file.read().replace('\n',''))
elif name.startswith('voltage') or name.startswith('energy') or name.startswith('power'):
payload[name] = round(float(file.read().replace('\n','')) / 1000000,2)
if name.startswith('voltage'):
unit = ' V' if SHOW_UNITS == '1' else ''
elif name.startswith('energy'):
unit = ' Wh' if SHOW_UNITS == '1' else ''
else:
unit = ' W' if SHOW_UNITS == '1' else ''
if SHOW_UNITS == '1':
payload[name] = str(round(float(file.read().replace('\n','')) / 1000000,2)) + unit
else:
payload[name] = round(float(file.read().replace('\n','')) / 1000000,2)
else:
payload[name] = file.read().replace('\n','')
except:
@@ -46,16 +57,23 @@ while True:
for name in ['energy_full_design', 'energy_full']:
with open(path + dir + '/' + name, 'r') as file:
health_calc[name] = int(file.read().replace('\n',''))
payload['battery_health'] = round((health_calc['energy_full'] / health_calc['energy_full_design']) * 100,2)
if SHOW_UNITS == '1':
payload['battery_health'] = str(round((health_calc['energy_full'] / health_calc['energy_full_design']) * 100,2)) + unit
else:
payload['battery_health'] = round((health_calc['energy_full'] / health_calc['energy_full_design']) * 100,2)
except:
pass
if TIME_REMAINING == '1':
unit = ' h' if SHOW_UNITS == '1' else ''
try:
for name in ['energy_now', 'power_now']:
with open(path + dir + '/' + name, 'r') as file:
time_remaining[name] = int(file.read().replace('\n',''))
payload['time_remaining'] = round((time_remaining['energy_now'] / time_remaining['power_now']),2)
if SHOW_UNITS == '1':
payload['time_remaining'] = str(round((time_remaining['energy_now'] / time_remaining['power_now']),2) if round((time_remaining['energy_now'] / time_remaining['power_now']),2) < 24 else '> 24') + unit
else:
payload['time_remaining'] = round((time_remaining['energy_now'] / time_remaining['power_now']),2) if round((time_remaining['energy_now'] / time_remaining['power_now']),2) < 24 else '> 24'
except:
pass