Power usage displayed on site


About 2.5 years ago I bought myself a new toy, the YouLess energy monitor. As the name suggests, it is an energy monitor. The YouLess monitors the total power consumption of my complete house, but it doesn’t monitor it per device.

The device is not cheap,it’s rather quite expensive. Nowdays there are multiple RaspberryPI based solutions which are cheaper, even if you don’t own a RaspberryPI yet. But anyway, it generates graphs, so money well spent 🙂 Plus it is a good way to make you aware of your power consumption. And that could mean energy saving. Even when it doesn’t monitor it per device, it is quite easy to tell if you turned on your dishwasher, or even a lightbulb.

The YouLess itself also contains a small webserver, which stores the historical power usage data. But the longer the timespan, the less detailed it becomes.  So since the day I received my YouLess I’ve been running a PHP script made by “magic_monkey“. A script is called each hour so that the most detailed data is stored in the database.

Recently I began writing a small script. Without scripting knowledge. I managed to pull out the current power usage from the YouLess, and store it in a file. So I could display the content of that file on the sidebar on my site. Job well done 🙂

But after a while, I was thinking that it could be a bit nicer than just a small text. There was only one solution for that: A graph! So I modified my script that it didn’t overwrite the current value each time, but added a new line to the file each time, from which I could pull the last lines I needed for the graph. With my lack of knowledge I was happy that I managed to do that. But I also knew that my method wasn’t very efficient, the datafile would grow and grow. So that would eventualy mean performance issues.

If you are still reading, and interested, this is my script:

#/bin/bash
FILE=/path/to/data_youless.txt
COUNT=`wc -l < $FILE`
if [ $COUNT -gt 12 ]; then

# If there are more than 12 lines, delete the oldest / first line, than add a new line.
sed -i".bak" '1d' $FILE
wget http://10.0.0.125/a -q -O - |grep Watt|sed s/\ Watt//|sed s/\,/\./|sed s/^\ // >> $FILE
else
# When there are less then 13 lines in the file just add lines.
wget http://10.0.0.125/a -q -O - |grep Watt|sed s/\ Watt//|sed s/\,/\./|sed s/^\ // >> $FILE
fi