diff --git a/src/mitsubishi2mqtt/html_metrics.h b/src/mitsubishi2mqtt/html_metrics.h
new file mode 100644
index 0000000..d6894d8
--- /dev/null
+++ b/src/mitsubishi2mqtt/html_metrics.h
@@ -0,0 +1,48 @@
+/*
+ mitsubishi2mqtt - Mitsubishi Heat Pump to MQTT control for Home Assistant.
+ Copyright (c) 2022 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved.
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+const char html_metrics[] PROGMEM = R"====(
+# HELP mitsubishi2mqtt_version Mitsubishi2MQTT version
+# TYPE mitsubishi2mqtt_version gauge
+mitsubishi2mqtt_version{hostname="_UNIT_NAME_",version="_VERSION_"} 1
+# HELP mitsubishi_power Heat pump power setting
+# TYPE mitsubishi_power gauge
+mitsubishi_power{hostname="_UNIT_NAME_"} _POWER_
+# HELP mitsubishi_temperature_room_celsius Current room temperature
+# TYPE mitsubishi_temperature_room_celsius gauge
+mitsubishi_temperature_room_celsius{hostname="_UNIT_NAME_"} _ROOMTEMP_
+# HELP mitsubishi_temperature_target_celsius Target room temperature
+# TYPE mitsubishi_temperature_target_celsius gauge
+mitsubishi_temperature_target_celsius{hostname="_UNIT_NAME_"} _TEMP_
+# HELP mitsubishi_fan_speed Heat pump fan speed
+# TYPE mitsubishi_fan_speed gauge
+mitsubishi_fan_speed{hostname="_UNIT_NAME_"} _FAN_
+# HELP mitsubishi_vane Heat pump vane setting
+# TYPE mitsubishi_vane gauge
+mitsubishi_vane{hostname="_UNIT_NAME_"} _VANE_
+# HELP mitsubishi_widevane Heat pump wide vane setting
+# TYPE mitsubishi_widevane gauge
+mitsubishi_widevane{hostname="_UNIT_NAME_"} _WIDEVANE_
+# HELP mitsubishi_mode Heat pump operating mode
+# TYPE mitsubishi_mode gauge
+mitsubishi_mode{hostname="_UNIT_NAME_"} _MODE_
+# HELP mitsubishi_operating Heat pump operational status
+# TYPE mitsubishi_operating gauge
+mitsubishi_operating{hostname="_UNIT_NAME_"} _OPER_
+# HELP mitsubishi_compressor_frequency Heat pump compressor frequency
+# TYPE mitsubishi_compressor_frequency gauge
+mitsubishi_compressor_frequency{hostname="_UNIT_NAME_"} _COMPFREQ_
+)====";
diff --git a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino
index 9d1e8ed..eafc20a 100644
--- a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino
+++ b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino
@@ -43,6 +43,7 @@ ESP8266WebServer server(80); // ESP8266 web
#include "html_init.h" // code html for initial config
#include "html_menu.h" // code html for menu
#include "html_pages.h" // code html for pages
+#include "html_metrics.h" // prometheus metrics
// Languages
#ifndef MY_LANGUAGE
#include "languages/en-GB.h" // default language English
@@ -132,6 +133,7 @@ void setup() {
server.on("/unit", handleUnit);
server.on("/status", handleStatus);
server.on("/others", handleOthers);
+ server.on("/metrics", handleMetrics);
server.onNotFound(handleNotFound);
if (login_password.length() > 0) {
server.on("/login", handleLogin);
@@ -994,6 +996,54 @@ void handleControl() {
//delay(100);
}
+void handleMetrics(){
+ String metrics = FPSTR(html_metrics);
+
+ heatpumpSettings currentSettings = hp.getSettings();
+ heatpumpStatus currentStatus = hp.getStatus();
+
+ String hppower = currentSettings.power == "ON" ? "1" : "0";
+
+ String hpfan = currentSettings.fan;
+ if(hpfan == "AUTO") hpfan = "-1";
+ if(hpfan == "QUIET") hpfan = "0";
+
+ String hpvane = currentSettings.vane;
+ if(hpvane == "AUTO") hpvane = "-1";
+ if(hpvane == "SWING") hpvane = "0";
+
+ String hpwidevane = "-2";
+ if(currentSettings.wideVane == "SWING") hpwidevane = "0";
+ if(currentSettings.wideVane == "<<") hpwidevane = "1";
+ if(currentSettings.wideVane == "<") hpwidevane = "2";
+ if(currentSettings.wideVane == "|") hpwidevane = "3";
+ if(currentSettings.wideVane == ">") hpwidevane = "4";
+ if(currentSettings.wideVane == ">>") hpwidevane = "5";
+ if(currentSettings.wideVane == "<>") hpwidevane = "6";
+
+ String hpmode = "-2";
+ if(currentSettings.mode == "AUTO") hpmode = "-1";
+ if(currentSettings.mode == "COOL") hpmode = "1";
+ if(currentSettings.mode == "DRY") hpmode = "2";
+ if(currentSettings.mode == "HEAT") hpmode = "3";
+ if(currentSettings.mode == "FAN") hpmode = "4";
+ if(hppower == "0") hpmode = "0";
+
+ metrics.replace("_UNIT_NAME_", hostname);
+ metrics.replace("_VERSION_", m2mqtt_version);
+ metrics.replace("_POWER_", hppower);
+ metrics.replace("_ROOMTEMP_", (String)currentStatus.roomTemperature);
+ metrics.replace("_TEMP_", (String)currentSettings.temperature);
+ metrics.replace("_FAN_", hpfan);
+ metrics.replace("_VANE_", hpvane);
+ metrics.replace("_WIDEVANE_", hpwidevane);
+ metrics.replace("_MODE_", hpmode);
+ metrics.replace("_OPER_", (String)currentStatus.operating);
+ metrics.replace("_COMPFREQ_", (String)currentStatus.compressorFrequency);
+ server.send(200, F("text/plain"), metrics);
+
+}
+
//login page, also called for logout
void handleLogin() {
bool loginSuccess = false;