diff --git a/src/httpserver/hass.c b/src/httpserver/hass.c index c6c575cce..66ea0c4d6 100644 --- a/src/httpserver/hass.c +++ b/src/httpserver/hass.c @@ -96,6 +96,9 @@ void hass_populate_unique_id(ENTITY_TYPE type, int index, char* uniq_id) { case PRESSURE_SENSOR: sprintf(uniq_id, "%s_%s_%d", longDeviceName, "pressure", index); break; + case HASS_TEMP: + sprintf(uniq_id, "%s_temp", longDeviceName); + break; case HASS_RSSI: sprintf(uniq_id, "%s_rssi", longDeviceName); break; @@ -281,6 +284,9 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, const char* p case ILLUMINANCE_SENSOR: sprintf(g_hassBuffer, "Illuminance"); break; + case HASS_TEMP: + sprintf(g_hassBuffer, "Temperature"); + break; case HASS_RSSI: sprintf(g_hassBuffer, "RSSI"); break; @@ -649,6 +655,13 @@ HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel, int cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer); cJSON_AddStringToObject(info->root, "val_tpl", g_template_lowMidHigh); + break; + case HASS_TEMP: + cJSON_AddStringToObject(info->root, "dev_cla", "temperature"); + cJSON_AddStringToObject(info->root, "stat_t", "~/temp"); + cJSON_AddStringToObject(info->root, "unit_of_meas", "°C"); + cJSON_AddStringToObject(info->root, "entity_category", "diagnostic"); + //cJSON_AddStringToObject(info->root, "icon_template", "mdi:access-point"); break; case HASS_RSSI: cJSON_AddStringToObject(info->root, "dev_cla", "signal_strength"); diff --git a/src/httpserver/hass.h b/src/httpserver/hass.h index 362f01a8e..1573811bb 100644 --- a/src/httpserver/hass.h +++ b/src/httpserver/hass.h @@ -65,6 +65,8 @@ typedef enum { READONLYLOWMIDHIGH_SENSOR, // lx unit ILLUMINANCE_SENSOR, + /// @brief °C unit + HASS_TEMP, /// @brief dBm unit HASS_RSSI, /// @brief Time firmware is alive in secs diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index c9d81a16c..aa5c5073e 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -2010,6 +2010,8 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { } if (1) { //use -1 for channel as these don't correspond to channels + dev_info = hass_init_sensor_device_info(HASS_TEMP, -1, -1, -1, 1); + MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN); dev_info = hass_init_sensor_device_info(HASS_RSSI, -1, -1, -1, 1); MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN); hass_free_device_info(dev_info); diff --git a/src/mqtt/new_mqtt.c b/src/mqtt/new_mqtt.c index fd6b07b73..92cfbd90e 100644 --- a/src/mqtt/new_mqtt.c +++ b/src/mqtt/new_mqtt.c @@ -1776,6 +1776,9 @@ void MQTT_init() CMD_RegisterCommand("publishFile", MQTT_PublishFile, NULL); #endif } +static float getInternalTemperature() { + return g_wifi_temperature; +} OBK_Publish_Result MQTT_DoItemPublishString(const char* sChannel, const char* valueStr) { @@ -1850,6 +1853,11 @@ OBK_Publish_Result MQTT_DoItemPublish(int idx) sprintf(dataStr, "%d", LWIP_GetActiveSockets()); return MQTT_DoItemPublishString("sockets", dataStr); + + case PUBLISHITEM_SELF_TEMP: + sprintf(dataStr, "%.2f", getInternalTemperature()); + return MQTT_DoItemPublishString("temp", dataStr); + case PUBLISHITEM_SELF_RSSI: sprintf(dataStr, "%d", HAL_GetWifiStrength()); return MQTT_DoItemPublishString("rssi", dataStr); diff --git a/src/mqtt/new_mqtt.h b/src/mqtt/new_mqtt.h index 66e0a0d3d..a8c8b2c36 100644 --- a/src/mqtt/new_mqtt.h +++ b/src/mqtt/new_mqtt.h @@ -23,20 +23,21 @@ void MQTT_BroadcastTasmotaTeleSTATE(); void MQTT_BroadcastTasmotaTeleSENSOR(); -#define PUBLISHITEM_ALL_INDEX_FIRST -16 +#define PUBLISHITEM_ALL_INDEX_FIRST -17 //These 3 values are pretty much static -#define PUBLISHITEM_SELF_STATIC_RESERVED_2 -16 -#define PUBLISHITEM_SELF_STATIC_RESERVED_1 -15 -#define PUBLISHITEM_SELF_HOSTNAME -14 //Device name -#define PUBLISHITEM_SELF_BUILD -13 //Build -#define PUBLISHITEM_SELF_MAC -12 //Device mac +#define PUBLISHITEM_SELF_STATIC_RESERVED_2 -17 +#define PUBLISHITEM_SELF_STATIC_RESERVED_1 -16 +#define PUBLISHITEM_SELF_HOSTNAME -15 //Device name +#define PUBLISHITEM_SELF_BUILD -14 //Build +#define PUBLISHITEM_SELF_MAC -13 //Device mac -#define PUBLISHITEM_DYNAMIC_INDEX_FIRST -11 +#define PUBLISHITEM_DYNAMIC_INDEX_FIRST -12 -#define PUBLISHITEM_QUEUED_VALUES -11 //Publish queued items +#define PUBLISHITEM_QUEUED_VALUES -12 //Publish queued items //These values are dynamic +#define PUBLISHITEM_SELF_TEMP -11 // Internal temp #define PUBLISHITEM_SELF_SSID -10 // SSID #define PUBLISHITEM_SELF_DATETIME -9 //Current unix datetime #define PUBLISHITEM_SELF_SOCKETS -8 //Active sockets