# How Beer mode works

- Link: https://www.samovar-tool.ru/en/2021/05/15/beer-mode-description/
- Published: 2021-05-15T00:48:41+03:00
- Author: kosoj.diy

Samovar supports a mode for mashing malt when brewing beer, preparing grain washes
and low-temperature cooking of food (sous-vide). The mode logic runs on a separate
control loop that understands eight types of program steps and works with parameters
of time, temperature, actuator and control sensor. You can control the mode from
the web interface, from the Android and iOS mobile apps, and from a page on the 
samovar-tool.ru website.

## Choosing the mode and addressing the sensors

Beer mode is selected in the Samovar settings. After the settings are saved, the
controller applies them without a reboot: the operating mode, the set of active 
sensors and the regulator parameters change.

Samovar remembers only the addresses of temperature sensors that were physically
connected to the bus at the moment the settings were saved. To avoid re-entering
the addresses every time you switch modes, save separate settings files with clear
names (for example, by mode) on your computer and load the one you need when changing
modes.

## Program line format

A Beer mode program is a set of lines separated by a space. Each line consists of
five fields separated by semicolons:

    ```wp-block-code
    TYPE;TEMPERATURE;TIME;DEVICE;SENSOR
    ```

 * **TYPE** — one of the values `M`, `P`, `B`, `C`, `F`, `W`, `L`, `A` (see the “
   Step types” section below).
 * **TEMPERATURE** — the target temperature, °C. For steps that do not use temperature,
   the field stays but the value is ignored.
 * **TIME** — duration in minutes. For steps that do not use time, put `0`.
 * **DEVICE** — the number of the actuator (for example, a stirrer or a valve) the
   step relates to. If the step is not tied to a specific device — `0`.
 * **SENSOR** — the index of the temperature sensor used to monitor the step. By
   default it is the boiler (`TankTemp`); for some steps you can specify the steam
   sensor or the column.

An example of a malt mashing program using the classic scheme with five temperature
rests:

    ```wp-block-code
    M;45.00;0;0;0 P;52.00;5;0;0 P;63.00;5;0;0 P;72.00;5;0;0 P;78.00;2;0;0 W;0.00;0;0;0 B;0.00;5;0;0 B;0.00;5;0;0 W;0.00;0;0;0 C;30.00;0;0;0
    ```

This program heats the mash to 45 °C (acid-protein rest), successively raises the
temperature to 52, 63, 72 and 78 °C with holds, waits for manual confirmation of
the malt addition and the start of the boil, then boils the wort with two hop additions,
waits for confirmation and cools to 30 °C.

## Mashing methods

Samovar has no fixed “infusion / decoction / saccharification” templates. The mashing
method is defined entirely by the program lines and the combination of step types.
Below are four typical methods that are most often used in practice. Any of them
is described by an ordinary Beer mode program.

### Infusion mashing with stepped heating

The most common method. The mash is heated in steps, with a rest of the required
length at each step. Each step is a pair of “heat to temperature” + “hold for the
set time”, plus manual confirmation of the malt addition at the start. The example
above shows the classic five-step scheme: 45 → 52 → 63 → 72 → 78 °C. The number 
of steps and their temperatures are up to the brewer: acid rest 35–45 °C, protein
rest 45–55 °C, saccharification 62–72 °C (for a sweet full-bodied beer — 68–72 °
C, for a dry one — 60–63 °C).

### Mashing with a single saccharification rest

A simplified method for light beer styles. The mash is heated to 52 °C and held,
then a single saccharification rest at 66–68 °C. The program:

    ```wp-block-code
    M;52.00;0;0;0 P;52.00;10;0;0 P;67.00;45;0;0 W;0.00;0;0;0 B;0.00;60;0;0 W;0.00;0;0;0 C;25.00;0;0;0
    ```

### Decoction

Part of the mash is taken into a separate vessel, brought to a boil and returned—
this raises the temperature of the main mash to the required step. In a Samovar 
program this looks like alternating heating steps and `W` steps: while the operator
pulls off, boils and returns the decoction, the controller waits for manual confirmation,
then moves on to the next step.

    ```wp-block-code
    M;45.00;0;0;0 P;45.00;15;0;0 W;0.00;0;0;0   -- mash-in, protein rest, manual confirmation before the decoction
    M;63.00;0;0;0 P;63.00;20;0;0 W;0.00;0;0;0   -- heating to saccharification, rest, manual confirmation
    P;72.00;30;0;0 W;0.00;0;0;0                  -- saccharification, manual confirmation
    B;0.00;60;0;0 W;0.00;0;0;0 C;25.00;0;0;0     -- boil with hops, cooling
    ```

### Two-vessel mashing (HI / HERMS / RIMS)

In setups with two vessels, the mash is filtered through a heated lauter tun (HI—
Heat Infusion), or through a heat exchanger in a separate vessel with its own temperature(
HERMS — Heat Exchange Recirculating Mash System), or recirculated through a RIMS
tube with a heater. In all cases the mash liquor and wort are recirculated; the 
temperature of the main mash is raised by heating in a separate loop rather than
by directly heating the boiler. In a Samovar program this method is also described
by `M`, `P` and `W` lines: while the operator sets up the flow and temperature in
the second vessel or in the RIMS loop, the controller holds the target temperature
and waits for manual confirmation before moving to the next step. If the loop is
controlled automatically via a relay or a servo drive, the transitions between steps
can be automated with an `L` step running its own Lua script (see the “Step types”
section).

    ```wp-block-code
    M;45.00;0;0;0 P;45.00;15;0;0 L;0;0;0;0     -- mash-in, protein rest, heating to the next step via the second vessel (Lua step)
    P;63.00;0;0;0 L;0;0;0;0                      -- saccharification with heating via the second vessel
    P;72.00;30;0;0 W;0.00;0;0;0                  -- final rest, manual confirmation
    B;0.00;60;0;0 W;0.00;0;0;0 C;25.00;0;0;0    -- boil with hops, cooling
    ```

The specific temperatures, hold times and number of steps depend on the recipe, 
the beer style and the layout of the setup. The program can be built for any mashing
method — Samovar executes it literally, without interfering in the logic between
lines.

## Importing recipes from BeerXML

The Samovar web interface can load recipes in BeerXML format (and the compatible
BrewMate) and automatically build a Beer mode program from them. This lets you bring
over recipes from third-party programs — BeerSmith, BrewMate and others — without
rewriting the lines by hand.

Path in the interface: _Beer mode → Import recipe_ (the `brewxml.htm` page).

 1. Choose the recipe’s XML file on your computer. BeerXML and BrewMate formats are
    supported — the module detects the format itself.
 2. The loaded file is parsed in the browser: the mashing, boiling and fermentation
    steps, volumes and ingredients are extracted.
 3. From this data, a sequence of temperature steps is built in the Samovar program
    format: pairs of “heat to temperature” + “hold”, boiling with hop additions, cooling.
 4. The generated program can be reviewed in the preview window, edited manually if
    needed and saved as an ordinary Beer mode program.

The reverse path is supported: a program written by hand can be saved to your computer
as a text file and reused later. The program format is plain text with lines of 
the form `TYPE;TEMPERATURE;TIME;DEVICE;SENSOR`, separated by a space.

## Step types

The following step types are available in Beer mode.

 * **`M` — heat to temperature with manual confirmation.** The controller heats 
   the mash to the set temperature and holds it until the operator moves on to the
   next line. When the temperature is reached, a notification is sent that the malt
   should be added.
 * **`P` — heat to temperature with automatic advance.** The controller heats to
   the set temperature and maintains it for the specified time, after which it automatically
   moves on to the next line.
 * **`B` — boil.** The controller boils for the set time. When the time is up, a
   notification is sent that hops should be added. If hops are added several times,
   several `B` lines are made with the corresponding intervals.
 * **`C` — cooling.** The controller opens the cooling water supply valve and waits
   until the temperature drops to the set value. After that the valve closes and
   the controller moves on to the next line. If the program lines have run out, 
   heating is switched off.
 * **`F` — final step.** Ends the program: switches off heating, valves and the 
   stirrer, and sends a completion notification.
 * **`W` — manual wait.** The controller does nothing until the operator manually
   moves on to the next line. Used for pauses that need a person: inspecting the
   mash, adding ingredients off schedule, taking samples.
 * **`L` — custom Lua step.** The controller calls the `beer.lua` script with the
   given context. The script controls external equipment, valves and the stirrer
   until it calls `setNextProgram()` or is stopped by a timeout. More details in
   the section on Lua scripts below.
 * **`A` — PID controller autotune.** The controller heats to the set temperature,
   then starts the autotune. When it finishes, the new coefficients are written 
   to the settings, heating is switched off and the controller requires a reboot.
   The process can take several hours; the accuracy of temperature holding improves
   after calibration. It is recommended to calibrate at the working voltage at which
   the regulator will operate.

## Heating control

Samovar controls heating through a power regulator: RM2, RMVK or kvic. The maximum
voltage is used for ramp-up (boost mode), and the working voltage set in the settings
is used for holding. When using RMVK or kvic, the working-mode voltage is set in
the settings; for other regulators the working voltage is fixed.

In builds with UART control (RMVK, kvic) a **boost heating element** is available:
when the boiler temperature is below the target by more than `ACCELERATION_HEATER_DELTA`(
4 °C by default, set in `Samovar_ini.h`), relay No. 4 (`RELE_CHANNEL4`) switches
on and powers an additional heating element. When the delta falls below the threshold,
the relay switches off and only the main heating works.

Relay No. 4 must be rated for a power at least 20% higher than that of the boost
heating element. If a four-relay module is used, it can switch a contactor or a 
more powerful relay.

## Temperature-reached hysteresis

The settings include the boiler temperature setpoint — the delta at which the controller
considers the set temperature reached. For example, if the setpoint is `0.1` for
the line `P;64.00;15;0;0`, the 15-minute countdown starts at a temperature of 63.9
°C.

## PID autotune

To start the PID controller autotune, set a separate two-line program:

    ```wp-block-code
    P;50.00;0;0;0
    A;50.00;0;0;0
    ```

The controller will heat to 50 °C, then start the calibration. When it finishes,
the new coefficients are written to the settings, heating switches off, and a reboot
is required. The coefficients can also be adjusted manually in the settings.

## Sous-vide

The sous-vide temperature mode is implemented as an ordinary Beer mode program with
a single hold line:

    ```wp-block-code
    P;65;300;0;0
    ```

The controller holds 65 °C for 300 minutes (5 hours), then sends a notification 
and switches off the heating. The food is vacuum-sealed in a bag beforehand. A separate
vacuum sealer is used for vacuum packing.

Samovar also has a separate Sous-vide mode with its own `suvid.lua` script and finer
temperature-holding logic. For one-off tasks Beer mode is enough; for regular cooking
it is recommended to use the dedicated mode.

## Logging and notifications

The controller keeps an operation log in its internal memory and sends data to the
samovar-tool.ru server. Notifications about key events — reaching a temperature 
rest, adding hops, the end of the program — are shown in the Android and iOS mobile
apps and on the control page on the samovar-tool.ru website. Alarm events arrive
as push notifications in the apps.

Sending readings over MQTT is optionally supported: the server, port, user, password
and topic are set in the local file `user_config_override.h` and are not stored 
in the device’s web interface. MQTT works without TLS and sends only the current
sensor values.

## What to know before starting

 * Before starting a program, check the temperature sensor addresses and save the
   settings on your computer — without a saved file you will have to enter the addresses
   again after a reboot.
 * The program starts automatically after a reboot; if you need to interrupt the
   process, use the stop button in the web interface or the `setAlarm()` command
   from Lua.
 * Lines without a numeric time (`M`, `W`) move on to the next step only on manual
   confirmation. If the operator does not confirm the transition, the program stays
   at the current step.
 * The `A` step (PID autotune) takes several hours. Do not start it unnecessarily
   and do not switch off the controller until it finishes.
 * The boost heating element switches on automatically when the temperature delta
   exceeds `ACCELERATION_HEATER_DELTA` (4 °C by default), if the firmware has the
   UART power regulator enabled (the `SAMOVAR_USE_POWER` flag in `Samovar_ini.h`)
   and the `RELE_CHANNEL4` pin is not occupied by another device. In other builds
   the boost heating element is not used.

### Like this:

Like Loading…

### _Related_
