Created
May 26, 2014 02:45
-
-
Save sergray/d4ff7d50063a2dbdece2 to your computer and use it in GitHub Desktop.
Store energy consumption in RRD files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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