Skip to content

Instantly share code, notes, and snippets.

@robweber
Created February 28, 2022 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robweber/d162a07ace09b501be180e8d54cc6f5c to your computer and use it in GitHub Desktop.
Save robweber/d162a07ace09b501be180e8d54cc6f5c to your computer and use it in GitHub Desktop.
Calculate energy based on load percent
"""calc_energy.py
calculate the energy usage based on a load percentage and max power rating
"""
def calc_energy(current_load, max_load, min=5, unit='W'):
# load percent * max load
current_power = (current_load/100) * max_load
# multiply the power by the time increment
# time increment should be in hours
Wh = current_power * (min/60)
if(unit == 'W'):
return {"watts": current_power, "watt_hours": Wh}
else:
return {"kilowatts": current_power/1000, "kilowatt_hours": Wh/1000}
# calculate 42% load at 600W max load
print(calc_energy(42, 600))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment