Skip to content

Commit

Permalink
adding backflush to MQTT
Browse files Browse the repository at this point in the history
add backflush editable vars to MQTT
add backflush to HA Discovery
cleanup ha discovery to be more verbose with publish
remove defaults in sensor/number device, they are to diffrent, default isn´t usefull

remove backflush from userconfig_sample
  • Loading branch information
LoQue90 authored and fiendie committed Oct 10, 2024
1 parent 295457c commit a7d1581
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
39 changes: 21 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,27 +1345,27 @@ void setup() {
.maxValue = BACKFLUSH_CYCLES_MAX,
.ptr = (void*)&backflushCycles};

editableVars["BACKFLUSH_FILLTIME"] = {.displayName = F("Backflush Fill Time (s)"),
.hasHelpText = true,
.helpText = "Time in seconds the pump is running during one backflush cycle",
.type = kDouble,
.section = sBrewSection,
.position = 18,
.show = [] { return true && FEATURE_BREWCONTROL == 1; },
.minValue = BACKFLUSH_FILL_TIME_MIN,
.maxValue = BACKFLUSH_FILL_TIME_MAX,
.ptr = (void*)&backflushFillTime};

editableVars["BACKFLUSH_FLUSHTIME"] = {.displayName = F("Backflush Flush Time (s)"),
editableVars["BACKFLUSH_FILL_TIME"] = {.displayName = F("Backflush Fill Time (s)"),
.hasHelpText = true,
.helpText = "Time in seconds the 3-way-valves stayes open during one backflush cycle",
.helpText = "Time in seconds the pump is running during one backflush cycle",
.type = kDouble,
.section = sBrewSection,
.position = 19,
.position = 18,
.show = [] { return true && FEATURE_BREWCONTROL == 1; },
.minValue = BACKFLUSH_FLUSH_TIME_MIN,
.maxValue = BACKFLUSH_FLUSH_TIME_MAX,
.ptr = (void*)&backflushFlushTime};
.minValue = BACKFLUSH_FILL_TIME_MIN,
.maxValue = BACKFLUSH_FILL_TIME_MAX,
.ptr = (void*)&backflushFillTime};

editableVars["BACKFLUSH_FLUSH_TIME"] = {.displayName = F("Backflush Flush Time (s)"),
.hasHelpText = true,
.helpText = "Time in seconds the 3-way-valves stayes open during one backflush cycle",
.type = kDouble,
.section = sBrewSection,
.position = 19,
.show = [] { return true && FEATURE_BREWCONTROL == 1; },
.minValue = BACKFLUSH_FLUSH_TIME_MIN,
.maxValue = BACKFLUSH_FLUSH_TIME_MAX,
.ptr = (void*)&backflushFlushTime};

editableVars["SCALE_WEIGHTSETPOINT"] = {.displayName = F("Brew weight setpoint (g)"),
.hasHelpText = true,
Expand Down Expand Up @@ -1576,8 +1576,11 @@ void setup() {

if (FEATURE_BREWCONTROL == 1) {
mqttVars["brewtime"] = [] { return &editableVars.at("BREW_TIME"); };
mqttVars["preinfusionpause"] = [] { return &editableVars.at("BREW_PREINFUSIONPAUSE"); };
mqttVars["preinfusion"] = [] { return &editableVars.at("BREW_PREINFUSION"); };
mqttVars["preinfusionPause"] = [] { return &editableVars.at("BREW_PREINFUSIONPAUSE"); };
mqttVars["backflushCycles"] = [] { return &editableVars.at("BACKFLUSH_CYCLES"); };
mqttVars["backflushFillTime"] = [] { return &editableVars.at("BACKFLUSH_FILL_TIME"); };
mqttVars["backflushFlushTime"] = [] { return &editableVars.at("BACKFLUSH_FLUSH_TIME"); };
}

if (FEATURE_SCALE == 1) {
Expand Down
26 changes: 22 additions & 4 deletions src/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ DiscoveryObject GenerateButtonDevice(String name, String displayName, String pay
* @param unit_of_measurement The unit of measurement for the sensor data (default: "°C")
* @return A `DiscoveryObject` containing the sensor device configuration
*/
DiscoveryObject GenerateSensorDevice(String name, String displayName, String unit_of_measurement = "°C", String device_class = "temperature") {
DiscoveryObject GenerateSensorDevice(String name, String displayName, String unit_of_measurement, String device_class) {
String mqtt_topic = String(mqtt_topic_prefix) + String(hostname);
DiscoveryObject sensor_device;
String unique_id = "clevercoffee-" + String(hostname);
Expand Down Expand Up @@ -457,7 +457,7 @@ DiscoveryObject GenerateSensorDevice(String name, String displayName, String uni
* @param ui_mode Control how the number should be displayed in the UI
* @return A `DiscoveryObject` containing the number device configuration
*/
DiscoveryObject GenerateNumberDevice(String name, String displayName, int min_value, int max_value, float steps_value, String unit_of_measurement = "°C", String ui_mode = "box") {
DiscoveryObject GenerateNumberDevice(String name, String displayName, int min_value, int max_value, float steps_value, String unit_of_measurement, String ui_mode = "box") {
String mqtt_topic = String(mqtt_topic_prefix) + String(hostname);
DiscoveryObject number_device;
String unique_id = "clevercoffee-" + String(hostname);
Expand Down Expand Up @@ -516,10 +516,19 @@ int sendHASSIODiscoveryMsg() {
DiscoveryObject aggTn = GenerateNumberDevice("aggTn", "aggTn", PID_TN_REGULAR_MIN, PID_TN_REGULAR_MAX, 0.1, "");
DiscoveryObject aggTv = GenerateNumberDevice("aggTv", "aggTv", PID_TV_REGULAR_MIN, PID_TV_REGULAR_MAX, 0.1, "");
DiscoveryObject aggIMax = GenerateNumberDevice("aggIMax", "aggIMax", PID_I_MAX_REGULAR_MIN, PID_I_MAX_REGULAR_MAX, 0.1, "");

#if FEATURE_BREWCONTROL == 1
DiscoveryObject brewtime = GenerateNumberDevice("brewtime", "Brew time", BREW_TIME_MIN, BREW_TIME_MAX, 0.1, "s");
DiscoveryObject preinfusion = GenerateNumberDevice("preinfusion", "Preinfusion filling time", PRE_INFUSION_TIME_MIN, PRE_INFUSION_TIME_MAX, 0.1, "s");
DiscoveryObject preinfusionPause = GenerateNumberDevice("preinfusionPause", "Preinfusion pause time", PRE_INFUSION_PAUSE_MIN, PRE_INFUSION_PAUSE_MAX, 0.1, "s");
DiscoveryObject backflushCycles = GenerateNumberDevice("backflushCycles", "Backflush Cycles", BACKFLUSH_CYCLES_MIN, BACKFLUSH_CYCLES_MAX, 1, "");
DiscoveryObject backflushFillTime = GenerateNumberDevice("backflushFillTime", "Backflush filling time", BACKFLUSH_FILL_TIME_MIN, BACKFLUSH_FILL_TIME_MAX, 0.1, "s");
DiscoveryObject backflushFlushTime = GenerateNumberDevice("backflushFlushTime", "Backflush flushing time", BACKFLUSH_FLUSH_TIME_MIN, BACKFLUSH_FLUSH_TIME_MAX, 0.1, "s");

#endif

// Sensor Devices
DiscoveryObject actual_temperature = GenerateSensorDevice("temperature", "Boiler Temperature");
DiscoveryObject actual_temperature = GenerateSensorDevice("temperature", "Boiler Temperature", "°C", "temperature");
DiscoveryObject heaterPower = GenerateSensorDevice("heaterPower", "Heater Power", "%", "power_factor");
DiscoveryObject machineStateDevice = GenerateSensorDevice("machineState", "Machine State", "", "enum");
DiscoveryObject currentWeight = GenerateSensorDevice("currentWeight", "Weight", "g", "weight");
Expand All @@ -531,7 +540,9 @@ int sendHASSIODiscoveryMsg() {
// Switch Devices
DiscoveryObject pidOn = GenerateSwitchDevice("pidON", "Use PID");
DiscoveryObject steamON = GenerateSwitchDevice("steamON", "Steam");
#if FEATURE_BREWCONTROL == 1
DiscoveryObject backflushOn = GenerateSwitchDevice("backflushOn", "Backflush");
#endif
DiscoveryObject startUsePonM = GenerateSwitchDevice("startUsePonM", "Use PonM");

// Button Devices
Expand All @@ -552,10 +563,17 @@ int sendHASSIODiscoveryMsg() {
actual_temperature,
heaterPower,
machineStateDevice,
#if FEATURE_BREWCONTROL == 1
brewtime,
preinfusion,
preinfusionPause,
backflushOn,
backflushCycles,
backflushFillTime,
backflushFlushTime,
#endif
pidOn,
steamON,
backflushOn,
startUsePonM

#if FEATURE_PRESSURESENSOR == 1
Expand Down
5 changes: 0 additions & 5 deletions src/userConfig_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ enum MACHINE {
#define SCALE_TYPE 0 // 0 = one HX711 per load cell, 1 = Only a single HX711 with two channels
#define SCALE_SAMPLES 2 // Load cell sample rate

// Backflush values
#define FILLTIME 5000 // time in ms the pump is running
#define FLUSHTIME 10000 // time in ms the 3-way valve is open -> backflush
#define MAXFLUSHCYCLES 5 // number of cycles the backflush should run, 0 = disabled

// PlatformIO OTA
#define OTA true // true = OTA activated, false = OTA deactivated
#define OTAPASS "otapass" // Password for OTA updates
Expand Down

0 comments on commit a7d1581

Please sign in to comment.