mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-26 15:57:16 +00:00
Fix future compiles using discovery
This commit is contained in:
parent
84ec331b62
commit
c6f51b8ca3
@ -22,8 +22,7 @@
|
|||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Tasmota discovery
|
* Tasmota discovery
|
||||||
*
|
*
|
||||||
* A version of xdrv_12_home_assistant supporting the new Tasmota Discovery used by
|
* Supported by latest versions of Home Assistant (with hatasmota) and TasmoManager.
|
||||||
* latest versions of Home Assistant or TasmoManager.
|
|
||||||
*
|
*
|
||||||
* SetOption19 0 - [DiscoverOff 0] [Discover 1] Enables discovery (default)
|
* SetOption19 0 - [DiscoverOff 0] [Discover 1] Enables discovery (default)
|
||||||
* SetOption19 1 - [DiscoverOff 1] [Discover 0] Disables discovery and removes retained message from MQTT server
|
* SetOption19 1 - [DiscoverOff 1] [Discover 0] Disables discovery and removes retained message from MQTT server
|
||||||
@ -129,7 +128,7 @@ void TasDiscoverMessage(void) {
|
|||||||
if (Shutter[i] != 0) { // Check if there are shutters present
|
if (Shutter[i] != 0) { // Check if there are shutters present
|
||||||
Relay[i] = 3; // Relay is a shutter
|
Relay[i] = 3; // Relay is a shutter
|
||||||
} else {
|
} else {
|
||||||
if (i >= light_idx || (iFanMod && (0 == i))) { // First relay on Ifan controls the light
|
if (i >= light_idx || (iFanMod && (0 == i))) { // First relay on Ifan controls the light
|
||||||
Relay[i] = 2; // Relay is a light
|
Relay[i] = 2; // Relay is a light
|
||||||
} else {
|
} else {
|
||||||
if (!iFanMod) { // Relays 2-4 for ifan are controlled by FANSPEED and don't need to be present if TasmotaGlobal.module_type = SONOFF_IFAN02 or SONOFF_IFAN03
|
if (!iFanMod) { // Relays 2-4 for ifan are controlled by FANSPEED and don't need to be present if TasmotaGlobal.module_type = SONOFF_IFAN02 or SONOFF_IFAN03
|
||||||
@ -228,14 +227,14 @@ void TasDiscovery(void) {
|
|||||||
TasmotaGlobal.masterlog_level = LOG_LEVEL_DEBUG_MORE; // Hide topic on clean and remove use weblog 4 to show it
|
TasmotaGlobal.masterlog_level = LOG_LEVEL_DEBUG_MORE; // Hide topic on clean and remove use weblog 4 to show it
|
||||||
|
|
||||||
ResponseClear(); // Clear retained message
|
ResponseClear(); // Clear retained message
|
||||||
if (!Settings->flag.hass_discovery) { // SetOption19 - Clear retained message
|
if (!Settings->flag.hass_discovery) { // SetOption19 - Clear retained message
|
||||||
TasDiscoverMessage(); // Build discovery message
|
TasDiscoverMessage(); // Build discovery message
|
||||||
}
|
}
|
||||||
char stopic[TOPSZ];
|
char stopic[TOPSZ];
|
||||||
snprintf_P(stopic, sizeof(stopic), PSTR("tasmota/discovery/%s/config"), NetworkUniqueId().c_str());
|
snprintf_P(stopic, sizeof(stopic), PSTR("tasmota/discovery/%s/config"), NetworkUniqueId().c_str());
|
||||||
MqttPublish(stopic, true);
|
MqttPublish(stopic, true);
|
||||||
|
|
||||||
if (!Settings->flag.hass_discovery) { // SetOption19 - Clear retained message
|
if (!Settings->flag.hass_discovery) { // SetOption19 - Clear retained message
|
||||||
Response_P(PSTR("{\"sn\":"));
|
Response_P(PSTR("{\"sn\":"));
|
||||||
MqttShowSensor(true);
|
MqttShowSensor(true);
|
||||||
ResponseAppend_P(PSTR(",\"ver\":1}"));
|
ResponseAppend_P(PSTR(",\"ver\":1}"));
|
||||||
@ -252,7 +251,7 @@ void TasRediscover(void) {
|
|||||||
|
|
||||||
void TasDiscoverInit(void) {
|
void TasDiscoverInit(void) {
|
||||||
if (ResetReason() != REASON_DEEP_SLEEP_AWAKE) {
|
if (ResetReason() != REASON_DEEP_SLEEP_AWAKE) {
|
||||||
Settings->flag.hass_discovery = 0; // SetOption19 - Enable Tasmota discovery and Disable legacy Hass discovery
|
Settings->flag.hass_discovery = 0; // SetOption19 - Enable Tasmota discovery and Disable legacy Hass discovery
|
||||||
TasmotaGlobal.discovery_counter = 10; // Delayed discovery
|
TasmotaGlobal.discovery_counter = 10; // Delayed discovery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,7 +294,7 @@ void CmndTasDiscover(void) {
|
|||||||
bool Xdrv12(uint8_t function) {
|
bool Xdrv12(uint8_t function) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (Settings->flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
if (Settings->flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
if (TasmotaGlobal.discovery_counter) {
|
if (TasmotaGlobal.discovery_counter) {
|
||||||
|
@ -1,23 +1,40 @@
|
|||||||
/*
|
/*
|
||||||
xdrv_12_home_assistant.ino - home assistant support for Tasmota
|
xdrv_12_home_assistant.ino - home assistant support for Tasmota
|
||||||
|
|
||||||
Copyright (C) 2021 Erik Montnemery, Federico Leoni and Theo Arends
|
Copyright (C) 2021 Erik Montnemery, Federico Leoni and Theo Arends
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef USE_HOME_ASSISTANT
|
#ifdef USE_HOME_ASSISTANT
|
||||||
#undef USE_TASMOTA_DISCOVERY
|
#undef USE_TASMOTA_DISCOVERY
|
||||||
|
/*********************************************************************************************\
|
||||||
|
* Legacy Home Assistant discovery now replaced by Tasmota Discovery and hatasmota in HASS
|
||||||
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XDRV_12 12
|
#define XDRV_12 12
|
||||||
|
|
||||||
|
#ifndef HOME_ASSISTANT_DISCOVERY_PREFIX
|
||||||
|
#define HOME_ASSISTANT_DISCOVERY_PREFIX "homeassistant" // Home Assistant discovery prefix
|
||||||
|
#endif
|
||||||
|
#ifndef HOME_ASSISTANT_LWT_TOPIC
|
||||||
|
#define HOME_ASSISTANT_LWT_TOPIC "homeassistant/status" // home Assistant Birth and Last Will Topic (default = homeassistant/status)
|
||||||
|
#endif
|
||||||
|
#ifndef HOME_ASSISTANT_LWT_SUBSCRIBE
|
||||||
|
#define HOME_ASSISTANT_LWT_SUBSCRIBE true // Subscribe to Home Assistant Birth and Last Will Topic (default = true)
|
||||||
|
#endif
|
||||||
|
|
||||||
// List of sensors ready for discovery
|
// List of sensors ready for discovery
|
||||||
const char kHAssJsonSensorTypes[] PROGMEM =
|
const char kHAssJsonSensorTypes[] PROGMEM =
|
||||||
D_JSON_TEMPERATURE "|" D_JSON_DEWPOINT "|" D_JSON_PRESSURE "|" D_JSON_PRESSUREATSEALEVEL "|"
|
D_JSON_TEMPERATURE "|" D_JSON_DEWPOINT "|" D_JSON_PRESSURE "|" D_JSON_PRESSUREATSEALEVEL "|"
|
||||||
@ -199,7 +216,16 @@ const char kHAssError3[] PROGMEM =
|
|||||||
uint8_t hass_mode = 0;
|
uint8_t hass_mode = 0;
|
||||||
int hass_tele_period = 0;
|
int hass_tele_period = 0;
|
||||||
|
|
||||||
// NEW DISCOVERY
|
/*********************************************************************************************\
|
||||||
|
* New discovery direct copy of Tasmota discovery
|
||||||
|
*
|
||||||
|
* Supported by latest versions of Home Assistant (with hatasmota) and TasmoManager.
|
||||||
|
*
|
||||||
|
* SetOption19 0 - [DiscoverOff 0] [Discover 1] Enables discovery (default)
|
||||||
|
* SetOption19 1 - [DiscoverOff 1] [Discover 0] Disables discovery and removes retained message from MQTT server
|
||||||
|
* SetOption73 1 - [DiscoverButton] Enable discovery for buttons
|
||||||
|
* SetOption114 1 - [DiscoverSwitch] Enable discovery for switches
|
||||||
|
\*********************************************************************************************/
|
||||||
void HassDiscoverMessage(void) {
|
void HassDiscoverMessage(void) {
|
||||||
uint32_t ip_address = (uint32_t)WiFi.localIP();
|
uint32_t ip_address = (uint32_t)WiFi.localIP();
|
||||||
char* hostname = TasmotaGlobal.hostname;
|
char* hostname = TasmotaGlobal.hostname;
|
||||||
@ -412,7 +438,10 @@ void NewHAssDiscovery(void) {
|
|||||||
|
|
||||||
TasmotaGlobal.masterlog_level = LOG_LEVEL_NONE; // Restore WebLog state
|
TasmotaGlobal.masterlog_level = LOG_LEVEL_NONE; // Restore WebLog state
|
||||||
}
|
}
|
||||||
// NEW DISCOVERY
|
|
||||||
|
/*********************************************************************************************\
|
||||||
|
* Legacy discovery
|
||||||
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void TryResponseAppend_P(const char *format, ...) {
|
void TryResponseAppend_P(const char *format, ...) {
|
||||||
#ifdef MQTT_DATA_STRING
|
#ifdef MQTT_DATA_STRING
|
||||||
|
Loading…
x
Reference in New Issue
Block a user