## 7. Clever Boiler Control

### 7.1 Switching on at High Solar Power

The dollhouse is equipped with a photovoltaic system. The current power is measured and can be subscribed to in the local network under the topic `meinHaus/Dach/Solarzelle/Leistung`.

Electric energy is notoriously difficult to store. This leads to many homeowners with photovoltaic systems having to sell their surplus electricity very cheaply to their grid operator. However, there may be devices in the house that can serve as energy storage:

- Electric car in the garage
- Electric boiler (for hot water)
- Freezers

Or devices that can be switched on flexibly in terms of time:

- Battery-operated devices
- Washing machine
- Tumbler

We want to turn on the electric boiler in the dollhouse when more than 70% power is available from the solar cells. Of course, in practice, the current consumption in the house would also have to be measured, but we simplify this in this school example.

Proceed as follows:

1. Take a look at the boiler dashboard (Tab Keller)
   1. Manually switch the boiler heating on and off (click on the lightning bolt).
   2. Turn the shower on and off.
   3. Observe what happens.
2. In Node-RED, go to the “Boiler Ladung” tab
3. Drag an `mqtt in` node into the flow area and configure it:
   1. Under Server, select Local MQTT Broker.
   2. Subscribe to the topic `meinHaus/Dach/Solarzelle/Leistung`
4. Use a debug node to examine what comes from the solar cell.
5. Drag a `switch` node into the flow area.
   1. Double-click on it to get to its configuration menu
   2. Forward the message from the solar cells to output 1 if the solar cell power exceeds 70%. Note that you must define the comparison value as a `number` (default is `string`) and specify it without '%'.
   3. Forward the message from the solar cells to output 2 if the solar cell power falls below 65%. Note that you must define the comparison value as a `number` (default is `string`) and specify it without '%'.

6. Drag two `change` nodes into the flow area, connecting them to output 1 and output 2 of the `switch` node, respectively. Change the payload of the current message to “on” or “off,” whichever makes sense to you.

7. Check with a debug node whether the logic works.

8. Now drag an `mqtt-out` node into the flow area.

9. Send “on” or “off” via MQTT to the boiler with the topic `meinHaus/UG/Boiler/Heizung`. Choose the local MQTT Broker for this.

10. Test with a flashlight and by covering the solar cell to see if anything happens at the boiler.

11. At the end, your flow should look like that: