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 = ''
broker = 'localhost'
broker_port = 1883

def energy(url):

    ret = -1
        response = urllib2.urlopen(url)
        data = json.loads(
        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)

    while True:
            watts = energy(URL)
            mqttc.publish('hw/youless', str(watts), 2)
            # mqttc.loop()
        except KeyboardInterrupt:

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 :-)

graphite preview

Cosm, the artist formerly know as “Pachube” provides a beta MQTT service which allows me to publish data into a feed. (The Mosquitto site has a good quick-start guide.)

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
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.

MQTT and Youless :: 10 Mar 2013 :: e-mail