# Re-Visiting Carnot’s Theorem

The proof by contradiction used in physics textbooks is one of those arguments that appear surprising, then self-evident, then deceptive in its simplicity. You – or maybe only: I – cannot resist turning it over and over in your head again, viewing it from different angles.

tl;dr: I just wanted to introduce the time-honored tradition of ASCII text art images to illustrate Carnot’s Theorem, but this post got out of hand when I mulled about how to  refute an erroneous counter-argument. As there are still research papers being written about Carnot’s efficiency I feel vindicated for writing a really long post though.

Carnot‘s arguments prove that there is a maximum efficiency of a thermodynamic heat engine – a machine that turns heat into mechanical energy. He gives the maximum value by evaluating one specific, idealized process, and then proves that a machine with higher efficiency would give rise to a paradox. The engine uses part of the heat available in a large, hot reservoir of heat and turns it into mechanical work and waste heat – the latter dumped to a colder ‘environment’ in a 4-step process. (Note that while our modern reformulation of the proof by contradiction refers to the Second Law of Thermodynamics, Carnot’s initial version was based on the caloric theory.)

The efficiency of such an engine η – mechanical energy per cycle over input heat energy – only depends on the two temperatures (More details and references here):

$\eta_\text{carnot} = \frac {T_1-T_2}{T_1}$

These are absolute temperatures in Kelvin; this universal efficiency can be used to define what we mean by absolute temperature.

I am going to use ‘nice’ numbers. To make ηcarnot equal to 1/2, the hot temperature
T1 = 273° = 546 K, and the colder ‘environment’ has T2 = 0°C = 273 K.

If this machine is run in reverse, it uses mechanical input energy to ‘pump’ energy from the cold environment to the hot reservoir – it is a heat pump using the ambient reservoir as a heat source. The Coefficient of Performance (COP, ε) of the heat pump is heat output over mechanical input, the inverse of the efficiency of the corresponding engine. εcarnot is 2 for the temperatures given above.

If we combine two such perfect machines – an engine and a heat pump, both connected to the hot space and to the cold environment, their effects cancel out: The mechanical energy released by the engine drives the heat pump which ‘pumps back’ the same amount of energy.

In the ASCII images energies are translated to arrows, and the number of parallel arrows indicates the amount of energy per cycle (or power). For each device, the number or arrows flowing in and out is the same; energy is always conserved. I am viewing this from the heat pump’s perspective, so I call the cold environment the source, and the hot environment room.

Neither of the heat reservoirs are heated or cooled in this ideal case as the same amount of energy flows from and to each of the heat reservoirs:

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| | | |                         | | | |
v v v v                         ^ ^ ^ ^
| | | |                         | | | |
|------------|                 |---------------|
|   Engine   |->->->->->->->->-|   Heat pump   |
|  Eta = 1/2 |->->->->->->->->-| COP=2 Eta=1/2 |
|------------|                 |---------------|
| |                             | |
v v                             ^ ^
| |                             | |
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

If either of the two machines works less than perfectly and in tandem with a perfect machine, anything is still fine:

If the engine is far less than perfect and has an efficiency of only 1/4 – while the heat pump still works perfectly – more of the engine’s heat energy input is now converted to waste heat and diverted to the environment:

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| | | |                           | |
v v v v                           ^ ^
| | | |                           | |
|------------|                 |---------------|
|   Engine   |->->->->->->->->-|   Heat pump   |
|  Eta = 1/4 |                 | COP=2 Eta=1/2 |
|------------|                 |---------------|
| | |                             |
v v v                             ^
| | |                             |
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

Now two net units of energy flow from the hot room to the environment (summing up the arrows to and from the devices):

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| |
v v
| |
|------------------|
|   Combination:   |
| Eta=1/4 COP=1/2  |
|------------------|
| |
v v
| |
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

Using a real-live heat pump with a COP of 3/2 (< 2) together with a perfect engine …

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| | | |                             | | |
v v v v                             ^ ^ ^
| | | |                             | | |
|------------|                 |-----------------|
|   Engine   |->->->->->->->->-|    Heat pump    |
|  Eta = 1/2 |->->->->->->->->-|     COP=3/2     |
|------------|                 |-----------------|
| |                                 |
v v                                 ^
| |                                 |
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

… causes again a non-paradoxical net flow of one unit of energy from the room to the environment.

In the most extreme case  a poor heat pump (not worth this name) with a COP of 1 just translates mechanical energy into heat energy 1:1. This is a resistive heating element, a heating rod, and net heat fortunately flows from hot to cold without paradoxes:

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| |                                |
v v                                ^
| |                                |
|------------|                 |-----------------|
|   Engine   |->->->->->->->->-|   'Heat pump'   |
|  Eta = 1/2 |                 |     COP = 1     |
|------------|                 |-----------------|
|
v
|
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

The textbook paradox in encountered, when an ideal heat pump is combined with an allegedly better-than-possible engine, e.g. one with an efficiency:

ηengine = 2/3 (> ηcarnot = 1/2)

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| | |                           | | | |
v v v                           ^ ^ ^ ^
| | |                           | | | |
|------------|                 |---------------|
|   Engine   |->->->->->->->->-|   Heat pump   |
|  Eta = 2/3 |->->->->->->->->-| COP=2 Eta=1/2 |
|------------|                 |---------------|
|                               | |
v                               ^ ^
|                               | |
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

The net effect / heat flow is then:

|----------------------------------------------------------|
|        Hot room at temperature T_1 = 273°C = 546 K       |
|----------------------------------------------------------|
|
^
|
|------------------|
|   Combination:   |
| Eta=3/2; COP=1/2 |
|------------------|
|
^
|
|----------------------------------------------------------|
|       Cold source at temperature T_2 = 0°C = 273 K       |
|----------------------------------------------------------|

One unit of heat would flow from the environment to the room, from the colder to the warmer body without any other change being made to the system. The combination of these machines would violate the Second Law of Thermodynamics; it is a Perpetuum Mobile of the Second Kind.

If the heat pump has a higher COP than the inverse of the perfect engine’s efficiency, a similar paradox arises, and again one unit of heat flows in the forbidden direction:

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| |                             | | |
v v                             ^ ^ ^
| |                             | | |
|------------|                 |---------------|
|   Engine   |->->->->->->->->-|   Heat pump   |
|  Eta = 1/2 |                 |    COP = 3    |
|------------|                 |---------------|
|                               | |
v                               ^ ^
|                               | |
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

A weird question: Can’t we circumvent the paradox if we pair the impossible superior engine with a poor heat pump?

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| | |                             | |
v v v                             ^ ^
| | |                             | |
|------------|                 |---------------|
|   Engine   |->->->->->->->->-|   Heat pump   |
|  Eta = 2/3 |->->->->->->->->-|    COP = 1    |
|------------|                 |---------------|
|
v
|
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------

Indeed: If the COP of the heat pump (= 1) is smaller than the inverse of the engine’s efficiency (3/2), there will be no apparent violation of the Second Law – one unit of net heat flows from hot to cold.

An engine with low efficiency 1/4 would ‘fix’ the second paradox involving the better-than-perfect heat pump:

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
| | | |                          | | |
v v v v                          ^ ^ ^
| | | |                          | | |
|------------|                 |---------------|
|   Engine   |->->->->->->->->-|   Heat pump   |
|  Eta = 1/4 |                 |     COP=3     |
|------------|                 |---------------|
| | |                            | |
v v v                            ^ ^
| | |                            | |
|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

But we cannot combine heat pumps and engines at will, just to circumvent the paradox – one counter-example is sufficient: Any realistic engine combined with any realistic heat pump – plus all combinations of those machines with ‘worse’ ones – have to result in net flow from hot to cold …

The Second Law identifies such ‘sets’ of engines and heat pumps that will all work together nicely. It’s easier to see this when all examples are condensed into one formula:

The heat extracted in total from the hot room – Q1 –  is the difference of heat used by the engine and heat delivered by the heat pump, both of which are defined in relation to the same mechanical work W:

$Q_1 = W\left (\frac{1}{\eta_\text{engine}}-\varepsilon_\text{heatpump}\right)$

This is also automatically equal to Qas another quick calculation shows or by just considering that energy is conserved: Some heat goes into the combination of the two machines, part of it – W – flows internally from the engine to the heat pump. But no part of the input Q1 can be lost, so the output of the combined machine has to match the input. Energy ‘losses’ such as energy due to friction will flow to either of the heat reservoirs: If an engine is less-then-perfect, more heat will be wasted to the environment; and if the heat pump is less-than-perfect a greater part of mechanical energy will be translated to heat only 1:1. You might be even lucky: Some part of heat generated by friction might end up in the hot room.

As Q1 has to be > 0 according to the Second Low, the performance numbers have to related by this inequality:

$\frac{1}{\eta_\text{engine}}\geq\varepsilon_\text{heatpump}$

The equal sign is true if the effects of the two machines just cancel each other.

If we start from a combination of two perfect machines (ηengine = 1/2 = 1/εheatpump) and increase either ηengine or εheatpump, this condition would be violated and heat would flow from cold to hot without efforts.

But also an engine with efficiency = 1 would work happily with the worst heat pump with COP = 1. No paradox would arise at first glance  – as 1/1 >= 1:

|----------------------------------------------------------|
|         Hot room at temperature T_1 = 273°C = 546 K      |
|----------------------------------------------------------|
|                                |
v                                ^
|                                |
|------------|                 |-----------------|
|   Engine   |->->->->->->->->-|   'Heat pump'   |
|   Eta = 1  |                 |      COP=1      |
|------------|                 |-----------------|

|----------------------------------------------------------|
|        Cold source at temperature T_2 = 0°C = 273 K      |
|----------------------------------------------------------|

What’s wrong here?

Because of conservation of energy ε is always greater equal 1; so the set of valid combinations of machines all consistent with each other is defined by:

$\frac{1}{\eta_\text{engine}}\geq\varepsilon_\text{heatpump}\geq1$

… for all efficiencies η and COPs / ε of machines in a valid set. The combination η = ε = 1 is still not ruled out immediately.

But if the alleged best engine (in a ‘set’) would have an efficiency of 1, then the alleged best heat pump would have an Coefficient of Performance of only 1 – and this is actually the only heat pump possible as ε has to be both lower equal and greater equal than 1. It cannot get better without creating paradoxes!

If one real-live heat pump is found that is just slightly better than a heating rod – say
ε = 1,1 – then performance numbers for the set of consisent, non-paradoxical machines need to fulfill:

$\eta_\text{engine}\leq\eta_\text{best engine}$

and

$\varepsilon_\text{heatpump}\leq\varepsilon_\text{best heatpump}$

… in addition to the inequality relating η and ε.

If ε = 1,1 is a candidate for the best heat pump, a set of valid machines would comprise:

• All heat pumps with ε between 1 and 1,1 (as per limits on ε)
• All engines with η between 0 and 0,9 (as per inequality following the Second Law plus limit on η).

Consistent sets of machines are thus given by a stronger condition – by adding a limit for both efficiency and COP ‘in between’:

$\frac{1}{\eta_\text{engine}}\geq\text{Some Number}\geq\varepsilon_\text{heatpump}\geq1$

Carnot has designed a hypothetical ideal heat pump that could have a COP of εcarnot = 1/ηcarnot. It is a limiting case of a reversible machine, but feasible on principle. εcarnot  is thus a valid upper limit for heat pumps, a candidate for Some Number. In order to make this inequality true for all sets of machines (ideal ones plus all worse ones) then 1/ηcarnot = εcarnot also constitutes a limit for engines:

$\frac{1}{\eta_\text{engine}}\geq\frac{1}{\eta_\text{carnot}}\geq\varepsilon_\text{heatpump}\geq1$

So in order to rule out all paradoxes, Some Number in Between has to be provided for each set of machines. But what defines a set? As machines of totally different making have to work with each other without violating this equality, this number can only be a function of the only parameters characterizing the system – the two temperatures

Carnot’s efficiency is only a function of the temperatures. His hypothetical process is reversible, the machine can work either as a heat pump or an engine. If we could come up with a better process for a reversible heat pump (ε > εcarnot), the machine run in reverse would be an engine with η less than ηcarnot, whereas a ‘better’ engine would lower the upper bound for heat pumps.

If you have found one truly reversible process, both η and ε associated with it are necessarily the upper bounds of performance of the respective machines, so you cannot push Some Number in one direction or the other, and the efficiencies of all reversible engines have to be equal – and thus equal to ηcarnot. The ‘resistive heater’ with ε = 1 is the iconic irreversible device. It will not turn into a perfect engine with η = 1 when ‘run in reverse’.

The seemingly odd thing is that 1/ηcarnot appears like a lower bound for ε at first glance if you just declare ηcarnot an upper bound for corresponding engines and take the inverse, while in practice and according to common sense it is the maximum value for all heat pumps, including irreversible ones. (As a rule of thumb a typical heat pump for space heating has a COP only 50% of 1/ηcarnot.)

But this ‘contradiction’ is yet another way of stating that there is one universal performance indicator of all reversible machines making use of two heat reservoirs: The COP of a hypothetical ‘superior’ reversible heat pump would be at least 1/ηcarnot  … as good as Carnot’s reversible machine, maybe better. But the same is true for the hypothetical superior engine with an efficiency of at least ηcarnot. So the performance numbers of all reversible machines (all in one set, characterized by the two temperatures) have to be exactly the same.

Historical piston compressor (from the time when engines with pistons looked like the ones in textbooks), installed 1878 in the salt mine of Bex, Switzerland. 1943 it was still in operation. Such machines used in salt processing were considered the first heat pumps.

# Hacking My Heat Pump – Part 2: Logging Energy Values

In the last post, I showed how to use Raspberry Pi as CAN bus logger – using a test bus connected to control unit UVR1611. Now I have connected it to my heat pump’s bus.

Credits for software and instructions:

Special thanks to SK Pang Electronics who provided me with CAN boards for Raspberry Pi after having read my previous post!!

CAN extension boards for Raspberry Pi, by SK Pang. Left: PiCAN 2 board (40 GPIO pins), right: smaller, retired PiCAN board with 26 GPIO pins – the latter fits my older Pi. In contrast to the board I used in the first tests, these have also a serial (DB9) interface.

Wiring CAN bus

We use a Stiebel-Eltron WPF 7 basic heat pump installed in 2012. The English website now refers to model WPF 7 basic s.

The CAN bus connections described in the German manual (Section 12.2.3) and the English manual (Wiring diagram, p.25) are similar:

CAN bus connections inside WPF 7 basic heat pump. For reference, see the description of the Physical Layer of the CAN protocol. Usage of the power supply (BUS +) is optional.

H, L and GROUND wires from the Pi’s CAN board are connected to the respective terminals inside the heat pump. I don’t use the optional power supply as the CAN board is powered by Raspberry Pi, and I don’t terminate the bus correctly with 120 Ω. As with the test bus, wires are rather short and thus have low resistance.

Heat pump with cover removed – CAN High (H – red), Low (L – blue), and Ground (yellow) are connected. The CAN cable is a few meters long and connects to the Raspberry Pi CAN board.

In the first tests Raspberry Pi had the privilege to overlook the heat pump room as the top of the buffer tank was the only spot the WLAN signal was strong enough …

Typical, temporary nerd’s test setup.

… or I used a cross-over ethernet cable and a special office desk:

Typical, temporary nerd’s workplace.

Now Raspberry Pi has its final position on the ‘organic controller board’, next to control unit UVR16x2 – and after a major upgrade to both LAN and WLAN all connections are reliable.

Raspberry Pi with PiCAN board from SK Pang and UVR16x2 control unit from Technische Alternative (each connected to a different CAN bus).

Bringing up the interface

According to messpunkt.org the bit rate of Stiebel-Eltron’s bus is 20000 bit/s; so the interface is activated with:

sudo ip link set can0 type can bitrate 20000
sudo ifconfig can0 up

Watching the idle bus

First I was simply watching with sniffer Wireshark if the heat pump says anything without being triggered. It does not – only once every few minutes there are two packets. So I need to learn to talk to it.

SK Pang provides an example of requesting data using open source tool cansend: The so-called CAN ID is followed by # and the actual data. This CAN ID refers to an ‘object’ – a set of properties of the device, like the set of inputs or outputs – and it can contain also the node ID of the device on the bus. There are many CAN tutorials on the net, I found this (German) introduction and this English tutorial very useful.

I was able to follow the communications of the two nodes in my test bus as I knew their node numbers and what to expect – the data logger would ask the controller for a set of configured sensor outputs every minute. Most packets sent by either bus member are related to object 480, indicating the transmission of a set of values (Process Data Exchange Objects, PDOs. More details on UVR’s CAN communication, in German)

Sniffing test CAN bus – communication of UVR1611 (node no 1) and logger BL-NET (node number 62 = be). Both devices use an ID related to object ID 480 plus their respective node number, as described here.

So I need to know object ID(s) and properly formed data values to ask the heat pump for energy readings – without breaking something by changing values.

Collecting interesting heat pump parameters for monitoring

I am very grateful for Jürg’s CAN tool can_scan that allow for querying a Stiebel-Eltron heat pump for specific values and also for learning about all possible parameters (listed in so-called Elster tables).

In order to check the list of allowed CAN IDs used by the heat pump I run:

./can_scan can0 680

can0 is the (default) name of the interface created earlier and 680 is my (the sender’s) CAN ID, one of the IDs allowed by can_scan.

Start of output:

elster-kromschroeder can-bus address scanner and test utility
copyright (c) 2014 Jürg Müller, CH-5524

scan on CAN-id: 680
list of valid can id's:

000 (8000 = 325-07)
180 (8000 = 325-07)
301 (8000 = 325-07)
480 (8000 = 325-07)
601 (8000 = 325-07)

In order to investigate available values and their meaning I run can_scan for each of these IDs:

./can_scan can0 680 180

Embedded below is part of the output, containing some of the values (and /* Comments */). This list of parameters is much longer than the list of values available via the display on the heat pump!

I am mainly interested in metered energies and current temperatures of the heat source (brine) and the ‘environment’ – to compare these values to other sensors’ output:

elster-kromschroeder can-bus address scanner and test utility
copyright (c) 2014 Jürg Müller, CH-5524

0001:  0000  (FEHLERMELDUNG  0)
0003:  019a  (SPEICHERSOLLTEMP  41.0)
0005:  00f0  (RAUMSOLLTEMP_I  24.0)
0006:  00c8  (RAUMSOLLTEMP_II  20.0)
0007:  00c8  (RAUMSOLLTEMP_III  20.0)
0008:  00a0  (RAUMSOLLTEMP_NACHT  16.0)
0009:  3a0e  (UHRZEIT  14:58)
000a:  1208  (DATUM  18.08.)
000c:  00e9  (AUSSENTEMP  23.3) /* Ambient temperature */
000d:  ffe6  (SAMMLERISTTEMP  -2.6)
000e:  fe70  (SPEICHERISTTEMP  -40.0)
0010:  0050  (GERAETEKONFIGURATION  80)
0013:  01e0  (EINSTELL_SPEICHERSOLLTEMP  48.0)
0016:  0140  (RUECKLAUFISTTEMP  32.0) /* Heating water return temperature */
...
01d4:  00e2  (QUELLE_IST  22.6) /* Source (brine) temperature */
...
/* Hot tap water heating energy MWh + kWh */
/* Daily totaly */
092a:  030d  (WAERMEERTRAG_WW_TAG_WH  781)
092b:  0000  (WAERMEERTRAG_WW_TAG_KWH  0)
/* Total energy since system startup */
092c:  0155  (WAERMEERTRAG_WW_SUM_KWH  341)
092d:  001a  (WAERMEERTRAG_WW_SUM_MWH  26)
/* Space heating energy, MWh + kWh */
/* Daily totals */
092e:  02db  (WAERMEERTRAG_HEIZ_TAG_WH  731)
092f:  0006  (WAERMEERTRAG_HEIZ_TAG_KWH  6)
/* Total energy since system startup */
0930:  0073  (WAERMEERTRAG_HEIZ_SUM_KWH  115)
0931:  0027  (WAERMEERTRAG_HEIZ_SUM_MWH  39)

Querying for one value

The the heating energy to date in MWh corresponds to index 0931:

./can_scan can0 680 180.0931

The output of can_scan already contains the sum of the MWh (0931) and kWh (0930) values:

elster-kromschroeder can-bus address scanner and test utility
copyright (c) 2014 Jürg Müller, CH-5524

value: 0027  (WAERMEERTRAG_HEIZ_SUM_MWH  39.115)

The network trace shows that the logger (using ID 680) queries for two values related to ID 180 – the kWh and the MWh part:

Network trace of Raspberry Pi CAN logger (ID 680) querying CAN ID 180. Since the returned MWh value is the sum of MWh and kWh value, two queries are needed. Detailed interpretation of packets in the text below.

Interpretation of these four packets – as explained on Jürg’s website here and here in German:

00 00 06 80 05 00 00 00 31 00 fa 09 31
00 00 01 80 07 00 00 00 d2 00 fa 09 31 00 27
00 00 06 80 05 00 00 00 31 00 fa 09 30
00 00 01 80 07 00 00 00 d2 00 fa 09 30 00 73
|---------| ||          |---| || |---| |---|
1)          2)          3)    4) 5)    6)

1) CAN-ID used by the sender: 180 or 680
2) No of bytes of data - 5 for queries, 8 for replies
3) CAN ID of the communications partner and type of message.
For queries the second digit is 1.
Pattern: n1 0m with n = 180 / 80 = 3 (hex) and m = 180 mod 7 = 0
(hex) Partner ID = 30 * 8 (hex) + 00 = 180
Responses follow a similar pattern using second digit 2:
Partner ID is: d0 * 8 + 00 = 680
4) fa indicates that the Elster index no is greater equal ff.
5) Index (parameter) queried for: 0930 for kWh and 0931 for MWh
6) Value returned 27h=39,73h=115

I am not sure which node IDs my logger and the heat pump use as the IDs. 180 seems to be an object ID without node ID added while 301 would refer to object ID + node ID 1. But I suppose with two devices on the bus only, and one being only a listener, there is no ambiguity.

Logging script

I found all interesting indices listed under CAN ID 180; so am now looping through this set once every three minutes with can_scan, cut out the number, and add it to a new line in a text log file. The CAN interfaces is (re-)started every time in case something happens, and the file is sent to my local server via FTP.

Every month a new log file is started, and log files – to be imported into my SQL Server  and processed as log files from UVR1611 / UVR16x2, the PV generator’s inverter, or the smart meter.

(Not the most elegant script – consider it a ‘proof of concept’! Another option is to trigger the sending of data with can_scan and collect output via can_logger.)

Interesting to-be-logged parameters are added to a ‘table’ – a file called indices:

0016 RUECKLAUFISTTEMP
01d4 QUELLE_IST
01d6 WPVORLAUFIST
091b EL_AUFNAHMELEISTUNG_WW_TAG_KWH
091d EL_AUFNAHMELEISTUNG_WW_SUM_MWH
091f EL_AUFNAHMELEISTUNG_HEIZ_TAG_KWH
0921 EL_AUFNAHMELEISTUNG_HEIZ_SUM_MWH
092b WAERMEERTRAG_WW_TAG_KWH
092f WAERMEERTRAG_HEIZ_TAG_KWH
092d WAERMEERTRAG_WW_SUM_MWH
0931 WAERMEERTRAG_HEIZ_SUM_MWH
000c AUSSENTEMP
0923 WAERMEERTRAG_2WE_WW_TAG_KWH
0925 WAERMEERTRAG_2WE_WW_SUM_MWH
0927 WAERMEERTRAG_2WE_HEIZ_TAG_KWH
0929 WAERMEERTRAG_2WE_HEIZ_SUM_MWH

Script:

# Define folders
logdir="/CAN_LOGS"
scriptsdir="/CAN_SCRIPTS"
indexfile="$scriptsdir/indices" # FTP parameters ftphost="FTP_SERVER" ftpuser="FTP_USER" ftppw="***********" # Exit if scripts not found if ! [ -d$scriptsdir ]
then
echo Directory $scriptsdir does not exist! exit 1 fi # Create log dir if it does not exist yet if ! [ -d$logdir ]
then
mkdir $logdir fi sleep 5 echo ====================================================================== # Start logging while [ 0 -le 1 ] do # Get current date and start new logging line now=$(date +'%Y-%m-%d;%H:%M:%S')
line=$now year=$(date +'%Y')
month=$(date +'%m') logfile=$year-$month-can-log-wpf7.csv logfilepath=$logdir/$logfile # Create a new file for every month, write header line if ! [ -f$logfilepath ]
then
while read indexline; do echo $indexline | cut -d" " -f2 done <$indexfile
echo "Datum Uhrzeit $headers" >$logfilepath
fi

# (Re-)start CAN interface
sudo ip link set can0 type can bitrate 20000
sudo ip link set can0 up

# Loop through interesting Elster indices
do
# Get output of can_scan for this index, search for line with output values
index=$(echo$indexline | cut -d" " -f1)
value=$($scriptsdir/./can_scan can0 680 180.$index | grep "value" | replace ")" "" | grep -o "\<[0-9]*\.\?[0-9]*$" | replace "." ",")
echo "$index$value"

# Append value to line of CSV file
line="$line;$value"
done < $indexfile # Write line to log file echo$line >> $logfilepath # echo FTP log file to server ftp -n -v$ftphost << END_SCRIPT
ascii
user $ftpuser$ftppw
binary
cd RPi
ls
lcd $logdir put$logfile
ls
bye
END_SCRIPT

echo "------------------------------------------------------------------"

# Wait - next logging data point
sleep 180

# Runs forever, use Ctrl+C to stop
done


In order to autostart the script I added a line to the rc.local file:

su pi -c '/CAN_SCRIPTS/pkt_can_monitor'

Using the logged values

In contrast to brine or water temperature heating energies are not available on the heat pump’s CAN bus in real-time: The main MWh counter is only incremented once per day at midnight. Then the daily kWh counter is added to the previous value.

Daily or monthly energy increments are calculated from the logged values in the SQL database and for example used to determine performance factors (heating energy over electrical energy) shown in our documentation of measurement data for the heat pump system.

# Hacking My Heat Pump – Part 1: CAN Bus Testing with UVR1611

In the old times, measuring data manually sometimes meant braving the elements:

White-Out in winter 2012/13! The barely visible wall is the solar/air collector of our heat pump system.

Measuring ground temperature in different depths.

Now, nearly all measurements are automated:

Online schematic of the heat pump system, showing the temperature and flow sensors needed for control, and a few of the sensors needed for monitoring only (radiation, ground temperature). Screenshot from CMI/UVR1611/UVR16x, Details on system’s operation in this post.

In order to calculate the seasonal performance factor of the heat pump system we have still used the ‘official’ energy reading provided by the heat pump’s display.

Can’t this be automated, too?

Our Stiebel-Eltron WPF7 basic is a simple brine/water heat pump without ‘smart’ features. Our control units turns it on and off via a latch contact.

But there are two interesting interfaces:

• An optical interface to connect a service PC.
• Wired connections to an internal CAN bus – a simple fieldbus used for example in vehicles.

We picked option 2 as it does not require an optical device to read off data. Our control unit also uses CAN bus, and we have test equipment for wired CAN connections.

I always want to use what we already have, and I had a Raspberry Pi not yet put into ‘productive’ use. As usual, you find geeks online who did already what you plan: Reading off CAN bus data provided by a Stiebel-Eltron heat pump using a Raspberry Pi.

In this first post, I am covering the test hardware setup. Before connecting to the heat pump I wanted to test with CAN devices I am familiar with.

Credits

I am indebted to the following sources for information and tools:

On Stiebel-Eltron heat pumps’ CAN bus plus Raspberry Pi

On Raspberry Pi and CAN bus in general / for other applications:

CAN converter

RPi has so-called GPIO pins that let you control devices in the real world. Talking to a CAN device requires an extension board to be connected to these pins.

My challenge: I had the older version – ‘Model B’ – with 26 GPIO pins only. The successor model B Plus had 40 pins. While the pin assignment was not changed, newer CAN extension boards (like this from SK Pang) were too large physically for the old Pi (The older, smaller board from SK Pang had been retired). I was glad to find this small board on ebay.

Edit, 2016-08-24: I replaced the board shown below by SK Pang’s retired PiCAN board – see part 2.

My Pi plus extension board:

CAN extension board connected to the Pi’s GPIO pins and to CAN bus (grey, three wires yellow, red, blue). Black (right) – electrical power, Blue (left): Ethernet. See more info on wiring below in the text.

Wiring the test CAN bus

The image shows the CAN board attached to the Pi, with CAN High, Low, and Ground connected. Following standards, CAN bus needs to be terminated on both ends, using a 120Ω resistor. As our wires are quite short and we had never observed issues with not / falsely terminated short CAN busses so far, we did not add proper termination (BTW: Thanks to ebay seller ZAB for providing the proper resistor!)

In the final setup, the other end of the CAN cable has to be connected to heat pump’s internal bus.

For testing purposes, I am building a CAN bus with three member devices:

1. Test control unit UVR1611 by Technische Alternative. This test unit does not control anything. A single temperature sensor is connected to check if logging works as expected.
2. The unit’s data logger BL-NET: The logger and the control unit communicate via CAN bus and logging data can be transferred to a PC via ethernet. For more details on using control units and loggers by Technische Alternative see this post.
3. My Raspberry Pi plus CAN board – connected to BL-NET.

Middle: Control unit UVR1611 (box with display), one Pt1000 temperature sensor connected (metal tube, black cable), Top: Data logger BL-NET (white box), connected to UVR1611 and Raspberry PI via CAN bus (grey CAN cables, blue plug). The yellow LAN / ethernet cable is for connecting a test PC.

I am using software WinSol on a PC connected via Ethernet to the data logger – to configure logging (BL-NET’s IP address) and to check if the temperature sensor works. BL-NET is set to log data every minute, so that I am sure that CAN packets are available on the bus often. More on WinSol and BL-NET here.

Activating CAN capabilities

Operating system update: I had first used the Raspberry Pi in 2014 using the Raspbian operating system, and I used a pre-installed SD card. Newer versions of the Raspbian Linux operating system do support CAN interfaces, so I just had to upgrade the kernel, described e.g. in CowFish’s instructions (see Software Installation section)

Operating system config: The CAN interface needs the underlying SPI bus – which has to be activated in the Pi’s configuration. This is described in detail on the blog of board vendor SK Pang.

Setting bit rate and bringing up the CAN interface

In order to check if software has been installed correctly, a virtual CAN interface can be configured as a rehearsal:

sudo modprobe vcan
sudo ip link set vcan0 up

This interface is not used, so sniffer software (as Wireshark, see below) will not show any communication.

If a physical CAN interface is activated if no CAN bus is physically connected an error cannot find device can0 is expected.

The critical parameter for the physical CAN bus is the bit rate of the bus. For an existing bus, you need to figure out its bit rate from documentation.

According to messpunkt.org the bit rate for the heat pump’s is 20kbit/s. UVR1611’s bus uses bit rate is 50kbit/s, so the interface is configured with

sudo ip link set can0 type can bitrate 50000
sudo ifconfig can0 up


Troubleshooting wrong bit rate

If this is not configured correctly, you will not get errors but you will simply don’t see any packets. Checking the CAN bus (with erroneously configured bit rate) with

sudo ip -s -d link show can0

showed that CAN state is BUS OFF …

Inspecting CAN bus performance details, having configured the UVR1611 bus (requiring 50kbit/s) with only 20kbit/s.

… a state the device can enter if there have been too many errors on the bus according to this documentation the CAN protocol family in Linux.

If the bit rate is set to 50000, packets are visible now.

Watching packets flowing by

I’ve installed Wireshark sniffer on the PI…

sudo apt-get install wireshark


… and selected the can0 interface. Packets are flowing, and Wireshark parses them correctly as CAN Protocol!

Network trace of CAN communications on the test CAN bus, consisting of UVR1611 and data logger BL-NET (Talking to each other) plus Raspberry Pi as silent sniffer.

If you know ‘how to speak CAN’ other devices on the bus can be polled for measurement values, using tools, like the Jürg’s CAN Progs or SK Pang’s Test tools linked at the bottom of this article.

In the next post in this series I will cover the setup of the Raspberry Pi CAN sniffer for the heat pump’s CAN bus.

>> Continued >> Part 2

# Self-Sufficiency Poetry

Our self-sufficiency quota for electrical energy is 30%, but what about the garden?

Since I haven’t smart metered every edible wildflower consumed, I resort to Search Term Poetry and random images. This is a summer blog post, lacking the usual number crunching and investigative tech journalism.

(Search terms are from WordPress statistics and Google Tools)

Direct self-consumption quota was nearly 100% last year (no preservation), and self-sufficiency was very low, with one exception: Yarrow tea.

This year we will reach 100% herbal tea self-sufficiency:

The solar/air collector is boosting yarrow harvest – and we have yet to include its cosmic quantum free energy focusing effect in the marketing brochure.

fringe science theories
can efficiency be greater than 1

But it also boosts vitality of other life forms:

alien energy

I cannot prove that these particular slimy aliens – edible and a protected species in Austria – are harmful as I never caught them red-handed. You just need to be careful when collecting vegetables to avoid the slimy parts.

We are self-sufficient re green ‘salad’ and ‘fake spinach’ for about half a year. Our top edible wild flowers in terms of yield are Dandelion, Fireweed, Meadow Goat’s Beard …

why does the grim reaper have a scythe

… and White Stonecrop: both tasty …

jurassic park jelly

… and ornamental:

zeitgeisty

With standard vegetables (accepted as edible by the majority) we did crop rotation – and the tomatoes look happiest as solitary plants in new places …

analyzing spatial models of choice and judgment

The Surprise Vegetable Award goes to an old heirloom variety, called Gartenmelde in German:

physics metaphors

Last year exactly one seedling showed up, and we left it untouched. This year the garden was flooded with purple plants in spring:

virtual zen garden

There are two main categories of edible plants – and two different branches of the food chain: Things we mainly eat, like tomatoes, herbs, onion, and garlic …

old-fashioned

… and the ones dedicated to alien species. Top example: The plants that should provide for our self-sufficiency in carbohydrates:

simple experiment

In the background of this image you see the helpful aliens in our garden, the ones that try to make themselves useful in this biosphere:

force on garden hose
so called art

But looking closer, there is another army of slimy life-forms, well organized and possibly controlled by a superior civilization in another dimension:

the matrix intro
protocol negotiation failed please try again

microwaving live animals

This garden is fertilizer- and pest-control-free, so we can only try to complement the food chain with proper – and more likeable – creatures:

solutions to problems

Yes, I have been told already it might not eat this particular variety of aliens as their slime is too bitter. I hope for some mutation!

But we are optimistic: We managed to tune in other life-forms to our philosophy as well and made them care about our energy technology:

so you want to be an engineer

This is a young blackbird. Grown up, it will skillfully de-slime and kill aliens, Men-in-Black-style.

Life-forms too quick or too small for our random snapshot photography deserve an honorable mention: Welcome, little snake (again an alien-killer) and thanks mason bees for clogging every hole or tube in the shed!

It is a pity I wasted the jurassic park search term on the snail already as of course we have pet dinosaurs:

So in summary, this biotope really has a gigantic bug, as we nerds say.

sniff all internet access

# First Year of Rooftop Solar Power and Heat Pump: Re-Visiting Economics

After I presented details for selected days, I am going to review overall performance in the first year. From June 2015 to May 2016 …

• … we needed 6.600 kWh of electrical energy in total.
• The heat pump consumed about 3.600 kWh of that …
• … in order to ‘pump it up to’ 16.800 kWh of heating energy (incl. hot tap water heating). This was a mild season! .
• The remaining 3.000kWh were used by household and office appliances, control, and circulation pumps.

(Disclaimer: I am from Austria –> decimal commas and dot thousands separator🙂

The photovoltaic generator …

• … harvested about 5.600kWh / year – not too bad for our 4,8kW system with panels oriented partly south-east and partly south-west.
• 2.000 kWh of that were used directly and the rest was fed into the grid.
• So 30% of our consumption was provided directly by the PV generator (self-sufficiency quota) and
• 35% of PV energy produced was utilized immediately (self-consumption quota).

Monthly energy balances show the striking difference between summer and winter: In summer the small energy needed to heat hot water can easily be provided by solar power. But in winter only a fraction of the energy needed can be harvested, even on perfectly sunny days.

Figures below show…

• … the total energy consumed in the house as the sum of the energy for the heat pump and the rest used by appliances …
• … and as the sum of energy consumed immediately and the rest provided by the utility.
• The total energy ‘generated’ by the solar panels, as a sum of the energy consumed directly (same aqua bar as in the sum of consumption) and the rest fed into the grid.

In June we needed only 300kWh (10kWh per day). The PV total output was more then 700kWh, and 200kW of that was directly delivered by the PV system – so the PV generator covered 65%. It would be rather easy to become autonomous by using a small, <10kWh battery and ‘shifting’ the missing 3,3kWh per day from sunny to dark hours.

But in January we needed 1100kWh and PV provided less than 200kWh in total. So a battery would not help as there is no energy left to be ‘shifted’.

Daily PV energy balances show that this is true for every single day in January:

We harvest typically less than 10 kWh per day, but we need  more than 30kWh. On the coldest days in January, the heat pump needed about 33kWh – thus heating energy was about 130kWh:

Our house’s heat consumption is typical for a well-renovated old building. If we would re-build our house from scratch, according to low energy standards, we might need only 50-60% energy at best. Then heat pump’s input energy could be cut in half (violet bar). But even then, daily total energy consumption would exceed PV production.

Economics

I have covered economics of the system without battery here and our system has lived up to the expectations: Profits were € 575, the sum of energy sales at market price  (€ 0,06 / kWh) and by not having to pay € 0,18 for power consumed directly.

In Austria turn-key PV systems (without batteries) cost about € 2.000 / kW rated power – so we earned about 6% of the costs. Not bad – given political discussions about negative interest rates. (All numbers are market prices, no subsidies included.)

But it is also interesting to compare profits to heating costs: In this season electrical energy needed for the heat pump translates to € 650. So our profits from the PV generator nearly amounts to the total heating costs.

Economics of batteries

Last year’s assessment of the economics of a system with battery is still valid: We could increase self-sufficiency from 30% to 55% using a battery and ‘shift’ additional 2.000 kWh to the dark hours. This would result in additional € 240 profits of per year.

If a battery has a life time of 20 years (optimistic estimate!) it must not cost more than € 5.000 to ever pay itself off. This is less than prices I have seen in quotes so far.

Off-grid living and autonomy

Energy autonomy might be valued more than economical profits. Some things to consider:

Planning a true off-grid system is planning for a few days in a row without sunshine. Increasing the size of the battery would not help: The larger the battery the larger the losses, and in winter the battery would never be full. It is hard to store thermal energy for another season, but it is even harder to store electrical energy. Theoretically, the area of panels could be massively oversized (by a factor – not a small investment), but then even more surplus has to be ‘wasted’ in summer.

The system has to provide enough energy per day and required peak load in every moment (see spikes in the previous post), but power needs also to be distributed to the 3 phases of electrical power in the right proportion: In Austria energy meters calculate a sum over 3 phases: A system might seem ‘autonomous’ when connected to the grid, but it would not be able to operate off-grid. Example: The PV generator produces 1kW per phase = 3kW in total, while 2kW are used by a water cooker on phase 1. The meter says you feed in 1kW to the grid, but technically you need 1kW extra from the grid for the water cooker and feed in 1kW on phase 2 and 3 each; so there is a surplus of 1kW in total. Disconnected from the grid, the water cooker would not work as 1kW is missing.

A battery does not provide off-grid capabilities automatically, nor do PV panels provide backup power when the sun is shining but the grid is down: During a power outage the PV system’s inverter has to turn off the whole system – otherwise people working on the power lines outside could be hurt by the power fed into the grid. True backup systems need to disconnect from the power grid safely first. Backup capabilities need to be compliant with local safety regulations and come with additional (potentially clunky / expensive) gadgets.

# Have I Seen the End of E-Mail?

Not that I desire it, but my recent encounters of ransomware make me wonder.

Some people in say, accounting or HR departments are forced to use e-mail with utmost paranoia. Hackers send alarmingly professional e-mails that look like invoices, job applications, or notifications of postal services. Clicking a link starts the download of malware that will encrypt all your data and ask for ransom.

Theoretically you could still find out if an e-mail was legit by cross-checking with open invoices, job ads, and expected mail. But what if hackers learn about your typical vendors from your business website or if they read your job ads? Then they would send plausible e-mails and might refer to specific codes, like the number of your job ad.

Until recently I figured that only medium or larger companies would be subject to targeted attacks. One major Austrian telco was victim of a Denial of Service attacked and challenged to pay ransom. (They didn’t, and were able to deal with the attack successfully.)

But then I have encountered a new level of ransomware attacks – targeting very small Austrian businesses by sending ‘expected’ job applications via e-mail:

• The subject line was Job application as [a job that had been advertised weeks ago at a major governmental job service platform]
• It was written in flawless German, using typical job applicant’s lingo as you learn in trainings.
• It was addressed to the personal e-mail of the employee dealing with applications, not the public ‘info@’ address of the business
• There was no attachment – so malware filters could not have found anything suspicious – but only a link to a shared cloud folder (‘…as the attachments are too large…’) – run by a a legit European cloud company.
• If you clicked the link (which you should not so unless you do this on a separate test-for-malware machine in a separate network) you saw a typical applicant’s photo and a second file – whose name translated to JobApplicationPDF.exe.

Suspicious features:

• The EXE file should have triggered red lights. But it is not impossible that a job application creates a self-extracting archive, although I would compare that to wrapping your paper application in a box looking like a fake bomb.
• Google’s Image Search showed that the photo has been stolen from a German photographer’s website – it was an example for a typical job applicant’s photo.
• Both cloud and mail service used were less known ones. It has been reported that Dropbox had removed suspicious files so it seemed that attackers tuned to alternative services. (Both mail and cloud provider reacted quickly and sht down the suspicious accounts)
• The e-mail did not contain a phone number or street address, just the pointer to the cloud store: Possible but weird as an applicant should be eager to encourage communications via all channels. There might be ‘normal’ issues with accessing a cloud store link (e.g. link falsely blocked by corporate firewall) – so the HR department should be able to call the applicant.
• Googling the body text of the e-mail gave one result only – a new blog entry of an IT professional quoting it at full length. The subject line was personalized to industry sector and a specific job ad – but the bulk of the text was not.
• The non-public e-mail address of the HR person was googleable as the job ad plus contact data appeared on a job platform in a different language and country, without the small company’s consent of course. So harvesting both e-mail address and job description automatically.

I also wonder if my Everything as a Service vision will provide a cure: More and more communication has been moved to messaging on social networks anyway – for convenience and avoiding false negative spam detection. E-Mail – powered by old SMTP protocol with tacked on security features, run on decentralized mail servers – is being replaced by messaging happening within a big monolithic block of a system like Facebook messaging. Some large employer already require their applications to submit their CVs using their web platforms, as well as large corporations demand that their suppliers use their billing platform instead of sending invoices per e-mail.

What needs to be avoided is downloading an executable file and executing it in an environment not controlled by security policies. A large cloud provider might have a better chance to enforce security, and viewing or processing an ‘attachment’ could happen in the provider’s environment. As an alternative all ‘our’ devices might be actually be part of a service and controlled more tightly by centrally set policies. Disclaimer: Not sure if I like that.

(‘Computer virus’ – from my first website 1997. Credits mine)

# Photovoltaic Generator and Heat Pump: Daily Power Generation and Consumption

You can generate electrical power at home but you cannot manufacture your own natural gas, oil, or wood. (I exempt the minority of people owning forestry). This is often an argument for the combination of heat pump and photovoltaic generator.

Last year I blogged in detail about economics of solar power and batteries and on typical power consumption and usage patterns – and my obsession with tracking down every sucker for electrical energy. Bottom line: Despite related tinkering with control and my own ‘user behaviour’ it is hard to raise self-consumption and self-sufficiency above statistical averages for homes without heat pumps.

In this post I will focus on load profiles and power generation during several selected days to illustrate these points, comparing…

• electrical power provided by the PV generator (logged at Fronius Symo inverter).
• input power needed by the heat pump (logged with energy meter connected to our control unit).
• … power balanced provided by the smart meter: Power is considered positive when fed into the grid is counted  (This meter is installed directly behind the utility’s meter)

A non-modulating, typical brine-water heat pump is always operating at full rated power: We have a 7kW heat pump – 7kW is about the design heat load of the building, as worst case estimate for the coldest day in years. On the coldest day in the last winter the heat pump was on 75% of the time.

Given a typical performance factor of 4 kWh/kWh), the heat pump needs 1/4 of its rated power as input. Thus the PV generator needs to provide about 1-2 kW when the heat pump is on. The rated power of our 18 panels is about 5kW – this is the output under optimum conditions.

Best result near winter solstice

If it is perfectly sunny in winter, the generator can produce enough energy to power the heat pump between 10:00 and 14:00 in the best case.

But such cloudless days are rare, and in the cold and long nights considerable electrical energy is needed, too.

Too much energy in summer

On a perfect summer day hot water could even be heated twice a day by solar power:

These peaks look more impressive than they are compared to the base load: The heat pump needs only 1-2kWh per day compared to 10-11kWh total consumption.

Harvesting energy in spring

On a sunny day in spring the PV output is higher than in summer due to lower ambient temperatures. As we still need space heating energy this energy can also be utilized better:

The heat pump’s input power is similar to the power of a water heater or an electrical stoves. At noon on a perfect day both the heat pump and one appliance could be run on solar power only.