diff --git a/include/YaSolRDefines.h b/include/YaSolRDefines.h index 9830503..abbc898 100644 --- a/include/YaSolRDefines.h +++ b/include/YaSolRDefines.h @@ -102,59 +102,61 @@ // configuration keys -#define KEY_DISPLAY_ROTATION "disp_angle" -#define KEY_DISPLAY_SPEED "disp_speed" -#define KEY_DISPLAY_TYPE "disp_type" -#define KEY_GRID_FREQUENCY "grid_freq" -#define KEY_GRID_POWER_MQTT_TOPIC "grid_pow_mqtt" -#define KEY_GRID_VOLTAGE_MQTT_TOPIC "grid_volt_mqtt" -#define KEY_HA_DISCOVERY_TOPIC "ha_disco_topic" -#define KEY_MQTT_PASSWORD "mqtt_pwd" -#define KEY_MQTT_PORT "mqtt_port" -#define KEY_MQTT_PUBLISH_INTERVAL "mqtt_pub_itvl" -#define KEY_MQTT_SECURED "mqtt_secure" -#define KEY_MQTT_SERVER "mqtt_server" -#define KEY_MQTT_TOPIC "mqtt_topic" -#define KEY_MQTT_USERNAME "mqtt_user" -#define KEY_NTP_SERVER "ntp_server" -#define KEY_NTP_TIMEZONE "ntp_timezone" -#define KEY_OUTPUT1_DAYS "o1_days" -#define KEY_OUTPUT1_DIMMER_MAX_DUTY "o1_dim_max_d" -#define KEY_OUTPUT1_DIMMER_MAX_TEMP "o1_dim_max_t" -#define KEY_OUTPUT1_RELAY_TYPE "o1_relay_type" -#define KEY_OUTPUT1_RESERVED_EXCESS "o1_excess_ratio" -#define KEY_OUTPUT1_RESISTANCE "o1_resistance" -#define KEY_OUTPUT1_TEMPERATURE_START "o1_temp_start" -#define KEY_OUTPUT1_TEMPERATURE_STOP "o1_temp_stop" -#define KEY_OUTPUT1_TIME_START "o1_time_start" -#define KEY_OUTPUT1_TIME_STOP "o1_time_stop" -#define KEY_OUTPUT2_DAYS "o2_days" -#define KEY_OUTPUT2_DIMMER_MAX_DUTY "o2_dim_max_d" -#define KEY_OUTPUT2_DIMMER_MAX_TEMP "o2_dim_max_t" -#define KEY_OUTPUT2_RELAY_TYPE "o2_relay_type" -#define KEY_OUTPUT2_RESERVED_EXCESS "o2_excess_ratio" -#define KEY_OUTPUT2_RESISTANCE "o2_resistance" -#define KEY_OUTPUT2_TEMPERATURE_START "o2_temp_start" -#define KEY_OUTPUT2_TEMPERATURE_STOP "o2_temp_stop" -#define KEY_OUTPUT2_TIME_START "o2_time_start" -#define KEY_OUTPUT2_TIME_STOP "o2_time_stop" -#define KEY_OUTPUT2_TIME_STOP "o2_time_stop" -#define KEY_PID_P_MODE "pid_pmode" -#define KEY_PID_D_MODE "pid_dmode" -#define KEY_PID_IC_MODE "pid_icmode" -#define KEY_PID_SETPOINT "pid_setpoint" -#define KEY_PID_KD "pid_kd" -#define KEY_PID_KI "pid_ki" -#define KEY_PID_KP "pid_kp" -#define KEY_PID_OUT_MAX "pid_out_max" -#define KEY_PID_OUT_MIN "pid_out_min" -#define KEY_RELAY1_LOAD "relay1_load" -#define KEY_RELAY1_TYPE "relay1_type" -#define KEY_RELAY2_LOAD "relay2_load" -#define KEY_RELAY2_TYPE "relay2_type" -#define KEY_UDP_PORT "udp_port" -#define KEY_WIFI_PASSWORD "wifi_pwd" -#define KEY_WIFI_SSID "wifi_ssid" +#define KEY_DISPLAY_ROTATION "disp_angle" +#define KEY_DISPLAY_SPEED "disp_speed" +#define KEY_DISPLAY_TYPE "disp_type" +#define KEY_GRID_FREQUENCY "grid_freq" +#define KEY_GRID_POWER_MQTT_TOPIC "grid_pow_mqtt" +#define KEY_GRID_VOLTAGE_MQTT_TOPIC "grid_volt_mqtt" +#define KEY_HA_DISCOVERY_TOPIC "ha_disco_topic" +#define KEY_MQTT_PASSWORD "mqtt_pwd" +#define KEY_MQTT_PORT "mqtt_port" +#define KEY_MQTT_PUBLISH_INTERVAL "mqtt_pub_itvl" +#define KEY_MQTT_SECURED "mqtt_secure" +#define KEY_MQTT_SERVER "mqtt_server" +#define KEY_MQTT_TOPIC "mqtt_topic" +#define KEY_MQTT_USERNAME "mqtt_user" +#define KEY_NTP_SERVER "ntp_server" +#define KEY_NTP_TIMEZONE "ntp_timezone" +#define KEY_OUTPUT1_DAYS "o1_days" +#define KEY_OUTPUT1_DIMMER_MAX_DUTY "o1_dim_max_d" +#define KEY_OUTPUT1_DIMMER_MAX_TEMP "o1_dim_max_t" +#define KEY_OUTPUT1_RELAY_TYPE "o1_relay_type" +#define KEY_OUTPUT1_RESERVED_EXCESS "o1_excess_ratio" +#define KEY_OUTPUT1_RESISTANCE "o1_resistance" +#define KEY_OUTPUT1_TEMPERATURE_MQTT_TOPIC "o1_temp_mqtt" +#define KEY_OUTPUT1_TEMPERATURE_START "o1_temp_start" +#define KEY_OUTPUT1_TEMPERATURE_STOP "o1_temp_stop" +#define KEY_OUTPUT1_TIME_START "o1_time_start" +#define KEY_OUTPUT1_TIME_STOP "o1_time_stop" +#define KEY_OUTPUT2_DAYS "o2_days" +#define KEY_OUTPUT2_DIMMER_MAX_DUTY "o2_dim_max_d" +#define KEY_OUTPUT2_DIMMER_MAX_TEMP "o2_dim_max_t" +#define KEY_OUTPUT2_RELAY_TYPE "o2_relay_type" +#define KEY_OUTPUT2_RESERVED_EXCESS "o2_excess_ratio" +#define KEY_OUTPUT2_RESISTANCE "o2_resistance" +#define KEY_OUTPUT2_TEMPERATURE_MQTT_TOPIC "o2_temp_mqtt" +#define KEY_OUTPUT2_TEMPERATURE_START "o2_temp_start" +#define KEY_OUTPUT2_TEMPERATURE_STOP "o2_temp_stop" +#define KEY_OUTPUT2_TIME_START "o2_time_start" +#define KEY_OUTPUT2_TIME_STOP "o2_time_stop" +#define KEY_OUTPUT2_TIME_STOP "o2_time_stop" +#define KEY_PID_P_MODE "pid_pmode" +#define KEY_PID_D_MODE "pid_dmode" +#define KEY_PID_IC_MODE "pid_icmode" +#define KEY_PID_SETPOINT "pid_setpoint" +#define KEY_PID_KD "pid_kd" +#define KEY_PID_KI "pid_ki" +#define KEY_PID_KP "pid_kp" +#define KEY_PID_OUT_MAX "pid_out_max" +#define KEY_PID_OUT_MIN "pid_out_min" +#define KEY_RELAY1_LOAD "relay1_load" +#define KEY_RELAY1_TYPE "relay1_type" +#define KEY_RELAY2_LOAD "relay2_load" +#define KEY_RELAY2_TYPE "relay2_type" +#define KEY_UDP_PORT "udp_port" +#define KEY_WIFI_PASSWORD "wifi_pwd" +#define KEY_WIFI_SSID "wifi_ssid" // pinout configuration keys diff --git a/include/YaSolRWebsite.h b/include/YaSolRWebsite.h index 893eb5f..1f6fa2d 100644 --- a/include/YaSolRWebsite.h +++ b/include/YaSolRWebsite.h @@ -196,6 +196,8 @@ namespace YaSolR { Card _haDiscoveryTopic = Card(&dashboard, TEXT_INPUT_CARD, YASOLR_LBL_105); Card _mqttGridVoltage = Card(&dashboard, TEXT_INPUT_CARD, YASOLR_LBL_106); Card _mqttGridPower = Card(&dashboard, TEXT_INPUT_CARD, YASOLR_LBL_107); + Card _mqttTempO1 = Card(&dashboard, TEXT_INPUT_CARD, YASOLR_LBL_181); + Card _mqttTempO2 = Card(&dashboard, TEXT_INPUT_CARD, YASOLR_LBL_182); Tab _pinConfigTab = Tab(&dashboard, "\u21C6 " YASOLR_LBL_108); Card _pinDisplayClock = Card(&dashboard, TEXT_INPUT_CARD, YASOLR_LBL_111); @@ -297,6 +299,7 @@ namespace YaSolR { void _pinout(Card& card, int32_t pin, std::map& pinout); void _status(Card& card, const char* key, bool enabled, bool state = true, const char* err = ""); void _temperature(Card& card, Mycila::DS18& sensor); + void _temperature(Card& card, Mycila::RouterOutput& output); }; extern WebsiteClass Website; diff --git a/include/i18n/en.h b/include/i18n/en.h index 9a456f9..307fdb1 100644 --- a/include/i18n/en.h +++ b/include/i18n/en.h @@ -184,8 +184,8 @@ #define YASOLR_LBL_178 "Debug Information" #define YASOLR_LBL_179 "ZCD Disabled" #define YASOLR_LBL_180 "Not paired" -#define YASOLR_LBL_181 -#define YASOLR_LBL_182 +#define YASOLR_LBL_181 "Output 1 Temperature MQTT Topic" +#define YASOLR_LBL_182 "Output 2 Temperature MQTT Topic" #define YASOLR_LBL_183 #define YASOLR_LBL_184 #define YASOLR_LBL_185 diff --git a/include/i18n/fr.h b/include/i18n/fr.h index bed7c5a..09bae81 100644 --- a/include/i18n/fr.h +++ b/include/i18n/fr.h @@ -184,8 +184,8 @@ #define YASOLR_LBL_178 "Informations de debug" #define YASOLR_LBL_179 "ZCD Désactivé" #define YASOLR_LBL_180 "Non associé" -#define YASOLR_LBL_181 -#define YASOLR_LBL_182 +#define YASOLR_LBL_181 "Topic MQTT pour la température sortie 1" +#define YASOLR_LBL_182 "Topic MQTT pour la température sortie 2" #define YASOLR_LBL_183 #define YASOLR_LBL_184 #define YASOLR_LBL_185 diff --git a/lib/MycilaRouter/MycilaGrid.h b/lib/MycilaRouter/MycilaGrid.h index 6dac0e6..6988973 100644 --- a/lib/MycilaRouter/MycilaGrid.h +++ b/lib/MycilaRouter/MycilaGrid.h @@ -39,7 +39,7 @@ namespace Mycila { // expiration for remote data void setExpiration(uint32_t seconds) { _expiration = seconds * 1000; } - void applyExpiration() { + void invalidate() { const uint32_t now = millis(); if (_meterTime > 0 && now - _meterTime >= _expiration) { diff --git a/lib/MycilaRouter/MycilaRouterOutput.cpp b/lib/MycilaRouter/MycilaRouterOutput.cpp index 4bccde3..2e75e76 100644 --- a/lib/MycilaRouter/MycilaRouterOutput.cpp +++ b/lib/MycilaRouter/MycilaRouterOutput.cpp @@ -147,10 +147,10 @@ void Mycila::RouterOutput::applyAutoBypass() { // temperature checks - const float temp = _temperatureSensor->getValidTemperature(); + const float temp = getValidTemperature(); - if (_temperatureSensor->isEnabled()) { - if (!_temperatureSensor->isValid()) { + if (isTemperatureEnabled()) { + if (!isTemperatureValid()) { if (_autoBypassEnabled) { LOGW(TAG, "Invalid temperature sensor value: stopping Auto Bypass '%s'...", _name); _autoBypassEnabled = false; diff --git a/lib/MycilaRouter/MycilaRouterOutput.h b/lib/MycilaRouter/MycilaRouterOutput.h index 95fb8a1..311c748 100644 --- a/lib/MycilaRouter/MycilaRouterOutput.h +++ b/lib/MycilaRouter/MycilaRouterOutput.h @@ -4,7 +4,6 @@ */ #pragma once -#include #include #include #include @@ -60,11 +59,9 @@ namespace Mycila { RouterOutput(const char* name, Dimmer& dimmer, Relay& relay, - DS18& temperatureSensor, PZEM& pzem) : _name(name), _dimmer(&dimmer), _relay(&relay), - _temperatureSensor(&temperatureSensor), _pzem(&pzem) {} // output @@ -86,12 +83,12 @@ namespace Mycila { #ifdef MYCILA_JSON_SUPPORT void toJson(const JsonObject& root, float gridVoltage) const { + root["bypass"] = isBypassOn() ? "on" : "off"; root["enabled"] = isDimmerEnabled(); root["state"] = getStateName(); - root["bypass"] = isBypassOn() ? "on" : "off"; + root["temperature"] = getValidTemperature(); _dimmer->toJson(root["dimmer"].to()); - _temperatureSensor->toJson(root["ds18"].to()); RouterOutputMetrics outputMeasurements; getMeasurements(outputMeasurements); @@ -122,7 +119,7 @@ namespace Mycila { bool isDimmerEnabled() const { return _dimmer->isEnabled(); } bool isAutoDimmerEnabled() const { return _dimmer->isEnabled() && config.autoDimmer && config.calibratedResistance > 0; } - bool isDimmerTemperatureLimitReached() const { return config.dimmerTempLimit > 0 && _temperatureSensor->isEnabled() && _temperatureSensor->getValidTemperature() >= config.dimmerTempLimit; } + bool isDimmerTemperatureLimitReached() const { return config.dimmerTempLimit > 0 && isTemperatureValid() && getValidTemperature() >= config.dimmerTempLimit; } uint16_t getDimmerDuty() const { return _dimmer->getDuty(); } float getDimmerDutyCycle() const { return _dimmer->getDutyCycle(); } // Power Duty Cycle [0, MYCILA_DIMMER_MAX_DUTY] @@ -198,6 +195,16 @@ namespace Mycila { } } + // temperature + + float getValidTemperature() const { return isTemperatureValid() ? _temperature : 0; } + bool isTemperatureEnabled() const { return _temperatureTime > 0; } + bool isTemperatureValid() const { return isTemperatureEnabled() && millis() - _temperatureTime < 60000; } + void updateTemperature(float temperature) { + _temperature = temperature; + _temperatureTime = millis(); + } + public: Config config; @@ -205,11 +212,12 @@ namespace Mycila { const char* _name; Dimmer* _dimmer; Relay* _relay; - Mycila::DS18* _temperatureSensor; PZEM* _pzem; bool _autoBypassEnabled = false; bool _bypassEnabled = false; RouterOutputStateCallback _callback = nullptr; + float _temperature = 0; + uint32_t _temperatureTime = 0; private: void _setBypass(bool state, bool log = true); diff --git a/src/Website.cpp b/src/Website.cpp index 16b27ce..2b8fd9a 100644 --- a/src/Website.cpp +++ b/src/Website.cpp @@ -200,6 +200,8 @@ void YaSolR::WebsiteClass::initLayout() { _mqttServerCert.setTab(&_mqttConfigTab); _mqttTopic.setTab(&_mqttConfigTab); _mqttUser.setTab(&_mqttConfigTab); + _mqttTempO1.setTab(&_mqttConfigTab); + _mqttTempO2.setTab(&_mqttConfigTab); _boolConfig(_haDiscovery, KEY_ENABLE_HA_DISCOVERY); _boolConfig(_mqttSecured, KEY_MQTT_SECURED); @@ -209,6 +211,8 @@ void YaSolR::WebsiteClass::initLayout() { _textConfig(_haDiscoveryTopic, KEY_HA_DISCOVERY_TOPIC); _textConfig(_mqttGridPower, KEY_GRID_POWER_MQTT_TOPIC); _textConfig(_mqttGridVoltage, KEY_GRID_VOLTAGE_MQTT_TOPIC); + _textConfig(_mqttTempO1, KEY_OUTPUT1_TEMPERATURE_MQTT_TOPIC); + _textConfig(_mqttTempO2, KEY_OUTPUT2_TEMPERATURE_MQTT_TOPIC); _textConfig(_mqttServer, KEY_MQTT_SERVER); _textConfig(_mqttTopic, KEY_MQTT_TOPIC); _textConfig(_mqttUser, KEY_MQTT_USERNAME); @@ -502,6 +506,8 @@ void YaSolR::WebsiteClass::initCards() { _haDiscoveryTopic.update(config.get(KEY_HA_DISCOVERY_TOPIC)); _mqttGridPower.update(config.get(KEY_GRID_POWER_MQTT_TOPIC)); _mqttGridVoltage.update(config.get(KEY_GRID_VOLTAGE_MQTT_TOPIC)); + _mqttTempO1.update(config.get(KEY_OUTPUT1_TEMPERATURE_MQTT_TOPIC)); + _mqttTempO2.update(config.get(KEY_OUTPUT2_TEMPERATURE_MQTT_TOPIC)); _mqttPort.update(config.get(KEY_MQTT_PORT)); _mqttPublishInterval.update(config.get(KEY_MQTT_PUBLISH_INTERVAL)); _mqttPwd.update(config.get(KEY_MQTT_PASSWORD).isEmpty() ? "" : HIDDEN_PWD); @@ -696,7 +702,7 @@ void YaSolR::WebsiteClass::updateCards() { _output1State.update(YASOLR_LBL_109, DASH_STATUS_DANGER); break; } - _temperature(_output1DS18State, ds18O1); + _temperature(_output1DS18State, output1); _output1DimmerSlider.update(dimmerO1.getDuty()); _output1DimmerSliderRO.update(dimmerO1.getDuty()); _output1Bypass.update(output1.isBypassOn()); @@ -727,7 +733,7 @@ void YaSolR::WebsiteClass::updateCards() { _output2State.update(YASOLR_LBL_109, DASH_STATUS_DANGER); break; } - _temperature(_output2DS18State, ds18O2); + _temperature(_output2DS18State, output2); _output2DimmerSlider.update(dimmerO2.getDuty()); _output2DimmerSliderRO.update(dimmerO2.getDuty()); _output2Bypass.update(output2.isBypassOn()); @@ -955,13 +961,23 @@ void YaSolR::WebsiteClass::_outputDimmerSlider(Card& card, Mycila::RouterOutput& void YaSolR::WebsiteClass::_temperature(Card& card, Mycila::DS18& sensor) { if (!sensor.isEnabled()) { card.update(YASOLR_LBL_115, ""); - } else if (sensor.getLastTime() == 0) { + } else if (!sensor.isValid()) { card.update(YASOLR_LBL_123, ""); } else { card.update(sensor.getValidTemperature(), "°C"); } } +void YaSolR::WebsiteClass::_temperature(Card& card, Mycila::RouterOutput& output) { + if (!output.isTemperatureEnabled()) { + card.update(YASOLR_LBL_115, ""); + } else if (!output.isTemperatureValid()) { + card.update(YASOLR_LBL_123, ""); + } else { + card.update(output.getValidTemperature(), "°C"); + } +} + void YaSolR::WebsiteClass::_status(Card& card, const char* key, bool enabled, bool active, const char* err) { const bool configEnabled = config.getBool(key); if (!configEnabled) diff --git a/src/init/Boot.cpp b/src/init/Boot.cpp index da18e2e..0e8a480 100644 --- a/src/init/Boot.cpp +++ b/src/init/Boot.cpp @@ -72,20 +72,22 @@ Mycila::Task bootTask("Boot", [](void* params) { config.configure(KEY_NTP_TIMEZONE, "Europe/Paris"); config.configure(KEY_OUTPUT1_DAYS, YASOLR_WEEK_DAYS); config.configure(KEY_OUTPUT1_DIMMER_MAX_DUTY, String(YASOLR_DIMMER_MAX_LEVEL)); - config.configure(KEY_OUTPUT1_DIMMER_MAX_TEMP, String(YASOLR_OUTPUT_AUTO_STOP_TEMPERATURE)); + config.configure(KEY_OUTPUT1_DIMMER_MAX_TEMP, "0"); config.configure(KEY_OUTPUT1_RELAY_TYPE, YASOLR_RELAY_TYPE_NO); config.configure(KEY_OUTPUT1_RESERVED_EXCESS, "100"); config.configure(KEY_OUTPUT1_RESISTANCE, "0"); + config.configure(KEY_OUTPUT1_TEMPERATURE_MQTT_TOPIC); config.configure(KEY_OUTPUT1_TEMPERATURE_START, String(YASOLR_OUTPUT_AUTO_START_TEMPERATURE)); config.configure(KEY_OUTPUT1_TEMPERATURE_STOP, String(YASOLR_OUTPUT_AUTO_STOP_TEMPERATURE)); config.configure(KEY_OUTPUT1_TIME_START, "22:00"); config.configure(KEY_OUTPUT1_TIME_STOP, "06:00"); config.configure(KEY_OUTPUT2_DAYS, YASOLR_WEEK_DAYS); config.configure(KEY_OUTPUT2_DIMMER_MAX_DUTY, String(YASOLR_DIMMER_MAX_LEVEL)); - config.configure(KEY_OUTPUT2_DIMMER_MAX_TEMP, String(YASOLR_OUTPUT_AUTO_STOP_TEMPERATURE)); + config.configure(KEY_OUTPUT2_DIMMER_MAX_TEMP, "0"); config.configure(KEY_OUTPUT2_RELAY_TYPE, YASOLR_RELAY_TYPE_NO); config.configure(KEY_OUTPUT2_RESERVED_EXCESS, "100"); config.configure(KEY_OUTPUT2_RESISTANCE, "0"); + config.configure(KEY_OUTPUT2_TEMPERATURE_MQTT_TOPIC); config.configure(KEY_OUTPUT2_TEMPERATURE_START, String(YASOLR_OUTPUT_AUTO_START_TEMPERATURE)); config.configure(KEY_OUTPUT2_TEMPERATURE_STOP, String(YASOLR_OUTPUT_AUTO_STOP_TEMPERATURE)); config.configure(KEY_OUTPUT2_TIME_START, "22:00"); diff --git a/src/init/Config.cpp b/src/init/Config.cpp index 265adba..8f8ffae 100644 --- a/src/init/Config.cpp +++ b/src/init/Config.cpp @@ -97,9 +97,6 @@ Mycila::Task initConfigTask("Init Config", [](void* params) { lights.begin(config.get(KEY_PIN_LIGHTS_GREEN).toInt(), config.get(KEY_PIN_LIGHTS_YELLOW).toInt(), config.get(KEY_PIN_LIGHTS_RED).toInt()); // DS18 - ds18Sys.setExpirationDelay(60); - ds18O1.setExpirationDelay(60); - ds18O2.setExpirationDelay(60); if (config.getBool(KEY_ENABLE_DS18_SYSTEM)) ds18Sys.begin(config.get(KEY_PIN_ROUTER_DS18).toInt()); if (config.getBool(KEY_ENABLE_OUTPUT1_DS18)) diff --git a/src/init/Events.cpp b/src/init/Events.cpp index b8c81bb..031b723 100644 --- a/src/init/Events.cpp +++ b/src/init/Events.cpp @@ -307,10 +307,12 @@ Mycila::Task initEventsTask("Init Events", [](void* params) { }); ds18O1.listen([](float temperature) { logger.info(TAG, "Output 1 Temperature changed to %.02f °C", temperature); + output1.updateTemperature(temperature); mqttPublishTask.requestEarlyRun(); }); ds18O2.listen([](float temperature) { logger.info(TAG, "Output 2 Temperature changed to %.02f °C", temperature); + output2.updateTemperature(temperature); mqttPublishTask.requestEarlyRun(); }); diff --git a/src/init/MQTT.cpp b/src/init/MQTT.cpp index eacc28d..95d657f 100644 --- a/src/init/MQTT.cpp +++ b/src/init/MQTT.cpp @@ -113,4 +113,26 @@ Mycila::Task initMqttSubscribersTask("Init MQTT Subscribers", [](void* params) { grid.updateMQTTGridVoltage(v); }); } + + // output 1 temperature + String output1TemperatureMQTTTopic = config.get(KEY_OUTPUT1_TEMPERATURE_MQTT_TOPIC); + if (!output1TemperatureMQTTTopic.isEmpty()) { + logger.info(TAG, "Reading Output 1 Temperature from MQTT topic: %s", output1TemperatureMQTTTopic.c_str()); + mqtt.subscribe(output1TemperatureMQTTTopic.c_str(), [](const String& topic, const String& payload) { + float t = payload.toFloat(); + logger.info(TAG, "Output 1 Temperature from MQTT: %f", t); + output1.updateTemperature(t); + }); + } + + // output 2 temperature + String output2TemperatureMQTTTopic = config.get(KEY_OUTPUT2_TEMPERATURE_MQTT_TOPIC); + if (!output2TemperatureMQTTTopic.isEmpty()) { + logger.info(TAG, "Reading Output 2 Temperature from MQTT topic: %s", output2TemperatureMQTTTopic.c_str()); + mqtt.subscribe(output2TemperatureMQTTTopic.c_str(), [](const String& topic, const String& payload) { + float t = payload.toFloat(); + logger.info(TAG, "Output 2 Temperature from MQTT: %f", t); + output2.updateTemperature(t); + }); + } }); diff --git a/src/init/REST.cpp b/src/init/REST.cpp index 96dda0e..5cdc3a7 100644 --- a/src/init/REST.cpp +++ b/src/init/REST.cpp @@ -25,6 +25,8 @@ Mycila::Task initRestApiTask("Init REST API", [](void* params) { relay1.toJson(root["relay1"].to()); relay2.toJson(root["relay2"].to()); router.toJson(root["router"].to(), grid.getVoltage()); + ds18O1.toJson(root["router"]["output1"]["ds18"].to()); + ds18O2.toJson(root["router"]["output2"]["ds18"].to()); zcd.toJson(root["zcd"].to()); response->setLength(); @@ -360,7 +362,7 @@ Mycila::Task initRestApiTask("Init REST API", [](void* params) { JsonObject json = root[output->getName()].to(); json["bypass"] = YASOLR_STATE(output->isBypassOn()); json["state"] = output->getStateName(); - json["temperature"] = ds18O1.getValidTemperature(); + json["temperature"] = output->getValidTemperature(); json["dimmer"]["duty"] = dimmerO1.getDuty(); json["dimmer"]["duty_cycle"] = dimmerO1.getDutyCycle(); diff --git a/src/main.cpp b/src/main.cpp index 2550e83..66da36a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,8 +36,8 @@ Mycila::Router router(pidController, jsy); Mycila::Dimmer dimmerO1(zcd); Mycila::Dimmer dimmerO2(zcd); -Mycila::RouterOutput output1("output1", dimmerO1, bypassRelayO1, ds18O1, pzemO1); -Mycila::RouterOutput output2("output2", dimmerO2, bypassRelayO2, ds18O2, pzemO2); +Mycila::RouterOutput output1("output1", dimmerO1, bypassRelayO1, pzemO1); +Mycila::RouterOutput output2("output2", dimmerO2, bypassRelayO2, pzemO2); Mycila::RouterRelay routerRelay1(relay1); Mycila::RouterRelay routerRelay2(relay2); diff --git a/src/tasks/Display.cpp b/src/tasks/Display.cpp index a99fb06..266e35a 100644 --- a/src/tasks/Display.cpp +++ b/src/tasks/Display.cpp @@ -125,8 +125,8 @@ Mycila::Task displayTask("Display", [](void* params) { display.home.printf("Output 1: %11.11s\n", output1.getStateName()); display.home.printf("Resistance: %4d Ohms\n", static_cast(round(outputMetrics.resistance))); display.home.printf("Dimmer: %5d %5d W\n", dimmerO1.getDuty(), static_cast(round(outputMetrics.power))); - if (ds18O1.isEnabled()) - display.home.printf("Temperature: %4.1f ", ds18O1.getValidTemperature()); + if (output1.isTemperatureValid()) + display.home.printf("Temperature: %4.1f ", output1.getValidTemperature()); else display.home.printf("Temperature: --.- "); display.home.printf("\xb0"); @@ -140,8 +140,8 @@ Mycila::Task displayTask("Display", [](void* params) { display.home.printf("Output 2: %11.11s\n", output2.getStateName()); display.home.printf("Resistance: %4d Ohms\n", static_cast(round(outputMetrics.resistance))); display.home.printf("Dimmer: %5d %5d W\n", dimmerO2.getDuty(), static_cast(round(outputMetrics.power))); - if (ds18O2.isEnabled()) - display.home.printf("Temperature: %4.1f ", ds18O2.getValidTemperature()); + if (output2.isTemperatureValid()) + display.home.printf("Temperature: %4.1f ", output2.getValidTemperature()); else display.home.printf("Temperature: --.- "); display.home.printf("\xb0"); diff --git a/src/tasks/MQTT.cpp b/src/tasks/MQTT.cpp index b7241f0..41bfeff 100644 --- a/src/tasks/MQTT.cpp +++ b/src/tasks/MQTT.cpp @@ -141,7 +141,7 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) { mqtt.publish(baseTopic + "/router/output1/bypass", YASOLR_STATE(output1.isBypassOn())); mqtt.publish(baseTopic + "/router/output1/state", output1.getStateName()); - mqtt.publish(baseTopic + "/router/output1/temperature", String(ds18O1.getValidTemperature(), 1)); + mqtt.publish(baseTopic + "/router/output1/temperature", String(output1.getValidTemperature(), 1)); mqtt.publish(baseTopic + "/router/output1/dimmer/duty", String(dimmerO1.getDuty())); mqtt.publish(baseTopic + "/router/output1/dimmer/duty_cycle", String(dimmerO1.getDutyCycle())); mqtt.publish(baseTopic + "/router/output1/dimmer/state", YASOLR_STATE(dimmerO1.isOn())); @@ -149,7 +149,7 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) { mqtt.publish(baseTopic + "/router/output2/bypass", YASOLR_STATE(output2.isBypassOn())); mqtt.publish(baseTopic + "/router/output2/state", output2.getStateName()); - mqtt.publish(baseTopic + "/router/output2/temperature", String(ds18O2.getValidTemperature(), 1)); + mqtt.publish(baseTopic + "/router/output2/temperature", String(output2.getValidTemperature(), 1)); mqtt.publish(baseTopic + "/router/output2/dimmer/duty", String(dimmerO2.getDuty())); mqtt.publish(baseTopic + "/router/output2/dimmer/duty_cycle", String(dimmerO2.getDutyCycle())); mqtt.publish(baseTopic + "/router/output2/dimmer/state", YASOLR_STATE(dimmerO2.isOn())); diff --git a/src/tasks/Router.cpp b/src/tasks/Router.cpp index 3892d9e..c5f3e00 100644 --- a/src/tasks/Router.cpp +++ b/src/tasks/Router.cpp @@ -6,7 +6,7 @@ #include Mycila::Task routerTask("Router", [](void* params) { - grid.applyExpiration(); + grid.invalidate(); output1.applyDimmerLimits(); output2.applyDimmerLimits();