The two spikes you see in the graph below were produced during lunch (a very good Carbonara sauce on bavette) and later while making popcorn.
I've fallen for MQTT and Mosquitto, and I thought it would be practical to grab the current electricity consumption from the Youless and hand it around via MQTT. Unfortunately, Youless doesn't (yet) support MQTT, so I had to obtain the current consumption it with a small Python program which polls the Youless and PUBlishes the current value to my MQTT broker:
#!/usr/bin/env python import paho.mqtt.client as paho # pip install paho-mqtt import urllib2 import json import time import sys URL = 'http://192.168.1.9/a?f=j' broker = 'localhost' broker_port = 1883 def energy(url): ret = -1 try: response = urllib2.urlopen(url) data = json.loads(response.read()) ret = data.get('pwr', -1) except Exception, e: print "Cannot get or decode %s: %s" % (url, str(e)) return ret if __name__ == '__main__': mqttc = paho.Client('youless-meter', clean_session=True) mqttc.connect(broker, broker_port, 60) mqttc.loop_start() while True: try: watts = energy(URL) mqttc.publish('hw/youless', str(watts), 2) # mqttc.loop() time.sleep(15) except KeyboardInterrupt: break except: raise mqttc.loop_stop() mqttc.disconnect()
This works well, but I wanted to graph the data (and I still haven't had the time to properly set up Graphite hereabouts, but it's coming: here a small example to whet your appetite :-)
Nick O’Leary had been there and done that so I followed his recommendation and added a bridge to Mosquitto which translates the topic name I used and bridges that into the Cosm data-stream. This is my Mosquitto configuration:
connection pachube_yl address api.cosm.com:1883 clientid n001 username 000000000000000000000000000000000000000000000000 topic "" out 0 hw/youless /v2/feeds/118350/datastreams/0.csv
As you can see from the screen-shot above, it works like a charm. (I must say though, that the Cosm's MQTT service has been a bit flaky from here: connections sometimes take ages to make; at other times, the data just doesn't arrive there.)
I've already contacted the guys at Youless to suggest it might well be worth their while to implement optional MQTT support in their firmware. I'm keeping my fingers crossed.