From eb3d3ba9b90de161a966e249ea45ff174558c26c Mon Sep 17 00:00:00 2001 From: fvanroie Date: Wed, 6 Jan 2021 23:19:35 +0100 Subject: [PATCH] Changes for HA --- src/svc/hasp_http.cpp | 10 +++++++--- src/svc/hasp_mqtt.cpp | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/svc/hasp_http.cpp b/src/svc/hasp_http.cpp index d36dce51..b191b0e2 100644 --- a/src/svc/hasp_http.cpp +++ b/src/svc/hasp_http.cpp @@ -231,9 +231,12 @@ void webHandleRoot() httpMessage += httpGetNodename(); httpMessage += F("
"); - httpMessage += F("

"); + httpMessage += + F("

"); + httpMessage += F("

"); + httpMessage += F("

"); httpMessage += F("

"); @@ -972,8 +975,9 @@ void webHandleConfig() httpMessage += F("

"); - httpMessage += - F("

"); + // httpMessage += + // F("

"); #if HASP_USE_GPIO > 0 httpMessage += diff --git a/src/svc/hasp_mqtt.cpp b/src/svc/hasp_mqtt.cpp index 6a863f7d..55f57fea 100644 --- a/src/svc/hasp_mqtt.cpp +++ b/src/svc/hasp_mqtt.cpp @@ -56,7 +56,8 @@ String mqttCommandTopic; // MQTT topic for incoming panel commands // String mqttGroupTopic((char *)0); char mqttNodeTopic[24]; char mqttGroupTopic[24]; -bool mqttEnabled; +bool mqttEnabled = false; +bool mqttHAautodiscover = false; //////////////////////////////////////////////////////////////////////////////////////////////////// // These defaults may be overwritten with values saved by the web interface @@ -173,6 +174,11 @@ void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const // data); } +void mqtt_ha_send_config() +{ + +} + //////////////////////////////////////////////////////////////////////////////////////////////////// // Receive incoming messages static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) @@ -198,6 +204,12 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length) dispatch_topic_payload(topic, (const char *)payload); return; + } else if(mqttHAautodiscover && topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic + if(!strcasecmp_P((char *)payload, PSTR("online"))) { + mqtt_ha_send_config(); + } + return; + } else { // Other topic Log.error(TAG_MQTT, F("Message received with invalid topic")); @@ -332,6 +344,9 @@ void mqttStart() mqttSubscribeTo(PSTR("%sbrightness/#"), mqttNodeTopic); mqttSubscribeTo(PSTR("%sLWT"), mqttNodeTopic); + /* Home Assistant auto-configuration */ + if(mqttHAautodiscover) mqttSubscribeTo(PSTR("homeassistant/status"), mqttClientId); + // Force any subscribed clients to toggle offline/online when we first connect to // make sure we get a full panel refresh at power on. Sending offline, // "online" will be sent by the mqttStatusTopic subscription action.