3-phase PV router
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1
14
15#pragma once
16
17#include "config_types.h" // the types and helpers used below (Load::local(), LOAD(), HOURS()...)
18
19// Motherboard: OLD for the former 3-phase board, NEW for the universal 3phaseDiverter board
20// (rev. 6.0 and later). A wrong choice gives wrong measurements: recalibrate after a change.
22
23// Serial output type - IoT, for the mk2Wifi module / Home Assistant (9600 baud, 7E1)
25
26// Debug messages (free RAM...) at startup. Whatever this setting, the startup configuration is
27// printed in every output (for IoT, at 8N1, before the 7E1 of the frames), and the status
28// messages in human-readable output only.
29inline constexpr bool ENABLE_DEBUG{ true };
30
31// Calibration mode: the router measures and logs as usual, but never switches any load
32// (TRIACs, relays, remote loads, overrides), as with the router OFF. With temperature sensing, it
33// also lists the sensors on the bus at startup, with their addresses for this file.
34// Set back to false once calibrated!
35inline constexpr bool CALIBRATION_MODE{ false };
36
37//--------------------------------------------------------------------------------------------------
38// Basic Configuration
39//
40inline constexpr uint8_t NO_OF_DUMPLOADS{ 3 };
41
42// ----------- Load map -----------
43//
44// One entry per dump load, in any order. Each entry says who drives the load:
45// Load::local(pin) - driven by the router itself, on that digital pin
46// Load::remote(unit) - driven by remote unit 'unit' (1..3), over RF
47// Load::remote(unit, ledPin) - same, plus a status LED on the router
48//
49// See the pinout notes further down for which pins are available.
50inline constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]{
51 Load::local(5),
52 Load::local(6),
54};
55
56// Feature toggles
57inline constexpr bool DIVERSION_PIN_PRESENT{ false };
58inline constexpr bool ROUTER_OFF_PIN_PRESENT{ false };
59inline constexpr RotationModes PRIORITY_ROTATION{ RotationModes::OFF };
60inline constexpr bool OVERRIDE_PIN_PRESENT{ true };
61
62inline constexpr bool WATCHDOG_PIN_PRESENT{ false };
63inline constexpr bool RELAY_DIVERSION{ false };
64inline constexpr bool DUAL_TARIFF{ false };
65inline constexpr bool TEMP_SENSOR_PRESENT{ false };
66inline constexpr bool RF_LOGGING_PRESENT{ false };
67
68// ----------- Pinout Assignments -----------
69//
70// ANALOG pins:
71// - All analog pins are reserved and hard-wired on the PCB.
72//
73// DIGITAL pins:
74// - D0 & D1: Reserved for the Serial interface.
75//
76// RFM69 module (RF data logging or remote loads):
77// - D2: Interrupt (IRQ).
78// - D10: Chip Select (CS).
79// - D11: Master Out Slave In (MOSI).
80// - D12: Master In Slave Out (MISO).
81// - D13: Serial Clock (SCK).
82//
83// mk2Wifi module (ESP32-C6, Home Assistant):
84// - D5 to D9 can be wired to the module, each through a solder jumper (open by default), as
85// inputs driven from Home Assistant: routing stop, router OFF, boost, priority rotation...
86// - Only close the jumpers of pins that are free in this configuration: by default, the loads
87// use D5, D6 and D7.
88
89// Load priority order at startup (array index = priority, 0 = highest)
90// Load indices refer to physicalLoadPin[] above, local and remote loads alike.
91inline constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]{ 0, 1, 2 };
92
93// Rotation groups: the loads that take turns at the top of the priority list, when
94// PRIORITY_ROTATION is not OFF. One group per appliance, e.g. the 3 elements of a water heater:
95// { { ALL_LOCAL_LOADS() } } - one heater, every local load
96// { { LOAD(0), LOAD(1), LOAD(2) }, { LOAD(3), LOAD(4), LOAD(5) } } - two heaters
97// Each group rotates among the priority places its loads hold; loads in no group never move.
98// A group has at least 2 loads, all local or all on the same remote unit, and a load is in one
99// group at most. Leave it empty, {}, without rotation.
100inline constexpr RotationGroups rotationGroups{};
101
102// Set the value to 'unused_pin' when the pin is not needed (feature deactivated)
103inline constexpr uint8_t dualTariffPin{ unused_pin };
104inline constexpr uint8_t diversionPin{ unused_pin };
105inline constexpr uint8_t routerOffPin{ unused_pin };
106inline constexpr uint8_t rotationPin{ unused_pin };
107inline constexpr uint8_t watchDogPin{ unused_pin };
108
109//--------------------------------------------------------------------------------------------------
110// EWMA Filter Tuning for Cloud Immunity
111//
112// The RELAY_FILTER_DELAY parameter controls how aggressively the EWMA filter smooths
113// power measurements before making relay decisions. This directly affects cloud immunity vs responsiveness.
114//
115// 🌤️ Quick Reference by Climate:
116// - Clear sky regions (desert, dry): 1 minute (fast response, minimal clouds)
117// - Mixed conditions (most locations): 2 minutes (recommended default)
118// - Frequently cloudy (coastal): 3 minutes (enhanced stability)
119// - Very cloudy (mountain, tropical): 4 minutes (maximum stability)
120//
121// 📖 Full guide: docs/Cloud_Pattern_Tuning_Guide.md, at the root of the repository
122//--------------------------------------------------------------------------------------------------
123inline constexpr uint8_t RELAY_FILTER_DELAY{ 2 };
124
125// Relay configuration with tunable EWMA filter
126// For battery systems, use negative import threshold (turn OFF when surplus < abs(threshold))
127// Examples:
128// Normal installation: { pin, 1000, 200, 5, 5 } // Turn OFF when importing > 200W
129// Battery installation: { pin, 1000, -50, 5, 5 } // Turn OFF when surplus < 50W
131 { { unused_pin, 100, 200, 1, 1 },
132 { unused_pin, 300, 400, 1, 1 },
133 { unused_pin, 500, 600, 1, 1 } } };
134
135// This is an example of override pin configuration.
136// You can modify the pin numbers and associated loads/relays as needed.
137// Ensure that the pins used do not conflict with other functionalities in your setup.
138//
139// Targets, in a list or alone:
140// LOAD(n) - load n of physicalLoadPin[], local or remote
141// LOCAL_LOAD(n) - Same as LOAD(n), for a load known to be local
142// REMOTE_LOAD(n) - the n-th REMOTE load: n counts remote loads only, in
143// physicalLoadPin[] order
144// RELAY(n) - relay n of relays
145// ALL_LOCAL_LOADS(), ALL_REMOTE_LOADS(), ALL_LOADS(), ALL_RELAYS(), ALL_LOADS_AND_RELAYS()
146// a number - that pin
147//
148// Example configurations:
149// inline constexpr OverridePins overridePins{
150// { { 4, ALL_LOADS() }, // Control all loads (local + remote)
151// { 5, ALL_LOCAL_LOADS() }, // Control only local loads
152// { 6, ALL_REMOTE_LOADS() }, // Control only remote loads
153// { 7, { LOAD(0), REMOTE_LOAD(1) } }, // Mixed: load 0 + the 2nd remote load
154// { 8, { LOAD(0), LOAD(1), LOAD(2), LOAD(3) } }, // Using LOAD() for any load index
155// { 9, ALL_LOADS_AND_RELAYS() } } }; // All loads and relays
156
157inline constexpr OverridePins overridePins{ { { 4, ALL_LOADS() } } };
158
159inline constexpr uint8_t ul_OFF_PEAK_DURATION{ 8 };
160
161// Scheduled boosts during the off-peak period (DUAL_TARIFF): when, and what they force.
162// Targets as for the override pins; what is not listed is never boosted.
163// Each window lies within the period; every boost stops when the meter switches back to peak.
164// FIRST(d) the first d of the period
165// LAST(d) the last d of the period
166// FROM_START(t), FOR(d) from t after the start, for d (without FOR: until the end)
167// BEFORE_END(t), FOR(d) from t before the end, for d (without FOR: until the end)
168// t and d: HOURS(n) or MINUTES(n)
169// inline constexpr ScheduledBoosts scheduledBoosts{ {
170// { FIRST(HOURS(2)), { LOAD(0), LOAD(2) } }, // loads #1 and #3, the first 2 hours
171// { LAST(MINUTES(90)), { RELAY(0) } } } }; // relay #1, the last 1 h 30
172inline constexpr ScheduledBoosts scheduledBoosts{ { { BEFORE_END(HOURS(3)), FOR(HOURS(2)), { LOAD(0) } } } };
173
174inline constexpr int16_t iTemperatureThreshold{ 100 };
175inline constexpr uint8_t BOOST_TEMP_SENSOR{ 0 };
176
178 { { 0x28, 0xBE, 0x41, 0x6B, 0x09, 0x00, 0x00, 0xA4 },
179 { 0x28, 0x1B, 0xD7, 0x6A, 0x09, 0x00, 0x00, 0xB7 } } };
180
181inline constexpr uint32_t ROTATION_AFTER_SECONDS{ 8UL * 3600UL };
The override pins, as in config.h: each pin with the targets it forces.
The relays, as in config.h: the sliding average and the settings of each relay.
The rotation groups, as in config.h: the loads that take turns at the top of the priority list,...
The scheduled boosts, as in config.h: each window with the targets it forces.
The temperature sensors, as in config.h: the pin of the bus and the address of each sensor.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition config.h:91
constexpr bool ROUTER_OFF_PIN_PRESENT
Definition config.h:58
constexpr ScheduledBoosts scheduledBoosts
Definition config.h:172
constexpr bool RELAY_DIVERSION
Definition config.h:63
constexpr bool OVERRIDE_PIN_PRESENT
Definition config.h:60
constexpr uint32_t ROTATION_AFTER_SECONDS
Definition config.h:181
constexpr uint8_t dualTariffPin
Definition config.h:103
constexpr TemperatureSensing temperatureSensing
Definition config.h:177
constexpr PcbVersion PCB_VERSION
Definition config.h:21
constexpr RelayEngine relays
Definition config.h:130
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition config.h:50
constexpr uint8_t RELAY_FILTER_DELAY
Definition config.h:123
constexpr bool RF_LOGGING_PRESENT
Definition config.h:66
constexpr bool DUAL_TARIFF
Definition config.h:64
constexpr uint8_t diversionPin
Definition config.h:104
constexpr OverridePins overridePins
Definition config.h:157
constexpr bool CALIBRATION_MODE
Definition config.h:35
constexpr SerialOutputType SERIAL_OUTPUT_TYPE
Definition config.h:24
constexpr bool ENABLE_DEBUG
Definition config.h:29
constexpr RotationGroups rotationGroups
Definition config.h:100
constexpr uint8_t NO_OF_DUMPLOADS
Definition config.h:40
constexpr uint8_t ul_OFF_PEAK_DURATION
Definition config.h:159
constexpr bool TEMP_SENSOR_PRESENT
Definition config.h:65
constexpr int16_t iTemperatureThreshold
Definition config.h:174
constexpr uint8_t routerOffPin
Definition config.h:105
constexpr bool WATCHDOG_PIN_PRESENT
Definition config.h:62
constexpr uint8_t BOOST_TEMP_SENSOR
Definition config.h:175
constexpr bool DIVERSION_PIN_PRESENT
Definition config.h:57
constexpr uint8_t rotationPin
Definition config.h:106
constexpr uint8_t watchDogPin
Definition config.h:107
What config.h is written with: its types, constants and helpers.
RotationModes
constexpr BoostStart BEFORE_END(const Minutes m)
A start m before the end of the off-peak period.
constexpr BoostLength FOR(const Minutes m)
A boost lasting m.
SerialOutputType
PcbVersion
constexpr uint8_t ALL_LOADS()
Every load, local and remote.
constexpr uint8_t LOAD(const uint8_t loadNum)
Load loadNum of physicalLoadPin[], local or remote (0, no load, if out of range).
constexpr uint8_t local(uint8_t pin)
Declares a load driven locally by the router.
Definition load_map.h:68
#define MINUTES(value)
A compile-time number of minutes, as an integral_constant.
#define HOURS(value)
A compile-time number of hours, as MINUTES().
constexpr uint8_t unused_pin
Definition utils_bits.h:20