Skip to content

Instantly share code, notes, and snippets.

@sergray
Created May 26, 2014 02:45
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 sergray/d4ff7d50063a2dbdece2 to your computer and use it in GitHub Desktop.
Save sergray/d4ff7d50063a2dbdece2 to your computer and use it in GitHub Desktop.
Store energy consumption in RRD files
#!/usr/bin/env python
from datetime import datetime
from subprocess import call
from mercury206 import commands, communications, config
def update_rrd(path, values):
value = ':'.join(['N'] + map(str, values))
call(['rrdtool', 'update', path, value])
print("Updated", path)
def add_readings(port, address):
readings = commands.display_readings(port, address)
update_rrd('tariffs.rrd', readings[:2])
def add_vcp(port, address):
voltage, current, power = commands.instant_vcp(port, address)
update_rrd('pcv.rrd', [power, current, voltage])
def main():
settings = config.get_settings()
port = communications.open_serial(settings['device'])
now = datetime.now()
if now.minute % 5 == 0:
add_vcp(port, settings['address'])
add_readings(port, settings['address'])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment