1 ===========================================
2 Ampy - The spying meter that doesn't snitch
3 ===========================================
5 Ampy is a tool to monitor your power consumption.
7 It is designed for self-hosting, without any third party analysing when you're home, when you wake up or what you are doing now.
14 You need a ampmeter sensor that outputs an audio signal.
16 It has been tested with `this YHDC sensor`_.
18 Installation is simple: You clip the sensor on the electrical line you want to measure on one side. On the other side, you plug the jack in your sound card.
20 **DISCLAMER**: You should check your sound card can handle the voltage. For example, my sensor maximum output is 1 volt, which is acceptable for the "mic" input of my sound card, but not for its "line in" input which is limited to 100mV. Nowadays, sound card are quite robust: I also tried the "line in" and it didn't fried the sound chip, but I strongly advise against you trying that. Don't blame me. Check the documentation of your hardware first.
22 .. _`this YHDC sensor`: https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/yhdc-sct-013-000-ct-sensor-report
33 * libapache2-mod-php | php-cgi | php-fpm
40 User setup and permissions
41 --------------------------
43 Ampy requires permission to use the sound card. It's recommanded to create a dedicated user::
45 addgroup --system ampy # create a dedicated group
46 adduser --system --ingroup ampy --home /var/lib/ampy --disabled-password --disabled-login ampy
47 adduser ampy audio # ampy can use audio
48 adduser www-data ampy # httpd in group ampy
53 Ampy uses the Round Robin Database provided by RRDtool.
55 The database can be set up with::
57 rrdtool create /var/lib/rrdcached/db/power.rrd \
59 DS:watts:GAUGE:1s:0:10000 \
60 RRA:AVERAGE:0.5:1s:1d \
61 RRA:AVERAGE:0.5:1m:3d \
62 RRA:AVERAGE:0.5:15m:1w \
63 RRA:AVERAGE:0.5:1h:30d \
64 RRA:AVERAGE:0.5:1d:3y \
66 RRA:AVERAGE:0.5:1month:10y \
67 RRA:MAX:0.5:1month:10y
68 chown ampy: /var/lib/rrdcached/db/power.rrd
69 chmod 664 /var/lib/rrdcached/db/power.rrd
72 rrdcached daemon helps being more efficient.
74 rrdcached socket must be available to both ampy daemon and apache.
76 Copy ``etc/rrdcached`` in ``/etc/default/rrdcached`` and adjust the ARGS parameter to match your program location.
83 Select the alsa audio input
84 ---------------------------
86 Run ``device.py`` to find out which entry you should use.
88 Then adjust DEVICE in run.py
90 A small ``record.py`` tool is available. It will give you a 50Hz .wav file with heigh proportional to your power consumption.
92 At this point, ``sudo -u ampy run.py --norecord`` should run and give you real time values.
97 Capture volume should be as high as possible, without clipping. A good value is 0 dB::
99 root:~# amixer -c 1 contents
100 numid=23,iface=mixer,name='capture volume'
101 ; type=integer,access=rw---r--,values=2,min=0,max=46,step=0
103 | dbscale-min=-16.00db,step=1.00db,mute=0
105 In that case volume should be set to 17.
107 You can also use ``alsamixer``. The control should show ``Capture [dB gain: 0.00, 0.00]``.
109 You should disable any *mic boost*. Set it to zero. Ampy likes to have the pure signal, with a simple exponential decibel scale, without any extra low volume super boost.
115 You'll need to adjust VOLUME_CONSTANT in run.py so that you get the correct voltage value.
120 When setup is done, daemon should be started automatically, for long term statistics::
122 cp etc/init /etc/init.d/ampy
123 update-rc.d ampy defaults
128 Just point your DocumentRoot to the ampy/html directory.
130 You should really password protect the access with something. Create a password file::
132 root:~# htpasswd /var/lib/ampy/htusers myusername
134 Then add something like that in your apache configuration file::
138 AuthName "Ampy's Realm"
139 AuthUserFile /var/lib/ampy/htusers
142 # Certbot / let's encrypt challenge dir has no password:
143 <Location /.well-known>
148 Counter initialization
149 ----------------------
151 If you have a regular electric meter::
153 echo "123456" > /var/lib/ampy/counter
154 chown ampy: /var/lib/ampy/counter
160 Copyright 2018-2019 Nirgal Vourgère
162 This program is free software: you can redistribute it and/or modify
163 it under the terms of the GNU General Public License as published by
164 the Free Software Foundation, either version 3 of the License, or
165 (at your option) any later version.
167 This program is distributed in the hope that it will be useful,
168 but WITHOUT ANY WARRANTY; without even the implied warranty of
169 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
170 GNU General Public License for more details.
172 You should have received a copy of the GNU General Public License
173 along with this program. If not, see http://www.gnu.org/licenses/.
176 Notes to cleanup (ignore that)
177 ==============================
181 rrdtool create power.rrd --daemon /var/run/rrdcached.sock --step 1s DS:watts:GAUGE:1:0:6600 RRA:AVERAGE:0.5:1s:1d
182 # Buggy: nécessite des updates toutes les 500 ms
185 Ceci n'est pas rafraîchi très souvent:
187 watch -n 0.5 rrdtool graphv - '-s' '1546280606' 'DEF:watts=/var/lib/rrdcached/db/power.rrd:watts:AVERAGE' 'VDEF:avg=watts,AVERAGE' 'VDEF:last=watts,LAST' 'PRINT:avg:%lf' 'PRINT:last:%lf'
189 watch -n 0.5 rrdtool lastupdate --daemon /var/run/rrdcached.sock /var/lib/rrdcached/db/power.rrd