[HA Discovery] Auto Off timer (#1541)
* [HA Discovery] Auto Off timer Auto deactivate discovery after 30min from the last activation, goal is to avoid unwanted entities created
This commit is contained in:
1 parent
9219ff928c
commit
3f92e14ba6
3 files changed
+14
-1
No files matched your search
@@ -13,7 +13,7 @@ From Home Assistant site
|
|||||||
|
|
||||||
On OpenMQTTGateway the Home Assistant discovery is enabled by default on all binaries and platformio configurations except for UNO. With Arduino IDE please read the [advanced configuration section](../upload/advanced-configuration#auto-discovery) of the documentation. Here are a few tips for activating discovery on Home Assistant, but for detailed configuration please refer to the Home Assistant website.
|
On OpenMQTTGateway the Home Assistant discovery is enabled by default on all binaries and platformio configurations except for UNO. With Arduino IDE please read the [advanced configuration section](../upload/advanced-configuration#auto-discovery) of the documentation. Here are a few tips for activating discovery on Home Assistant, but for detailed configuration please refer to the Home Assistant website.
|
||||||
|
|
||||||
Enable discovery on your MQTT integration in HASS.
|
Enable discovery on your MQTT integration in HASS (activated per default).
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -36,6 +36,9 @@ OMG will use the auto discovery functionality of home assistant to create gatewa
|
|||||||
::: info
|
::: info
|
||||||
The Bluetooth and the RTL_433 gateway will create automatically devices and entities, the RF gateway will create DeviceTrigger.
|
The Bluetooth and the RTL_433 gateway will create automatically devices and entities, the RF gateway will create DeviceTrigger.
|
||||||
The OpenMQTTGateway will also be available as a device to monitor its parameters and control it. The sensors (DHT for example) and actuators (relays) are attached to the gateway.
|
The OpenMQTTGateway will also be available as a device to monitor its parameters and control it. The sensors (DHT for example) and actuators (relays) are attached to the gateway.
|
||||||
|
|
||||||
|
30 minutes after its activation the auto discovery will be automaticaly deactivated, you can reactivate it from the gateway controls.
|
||||||
|
Some devices may require a button push or motion/contact event to trigger a message and generate the auto discovery.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
## RTL_433 auto discovery specificity
|
## RTL_433 auto discovery specificity
|
||||||
|
|||||||
@@ -121,6 +121,10 @@ void announceDeviceTrigger(bool use_gateway_info,
|
|||||||
# define discovery_republish_on_reconnect false
|
# define discovery_republish_on_reconnect false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DiscoveryAutoOffTimer
|
||||||
|
# define DiscoveryAutoOffTimer 1800000 // Timer (ms) that trigger auto discovery to off after activation, the goal is to avoid the discovery of entities that are not expected
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef GATEWAY_MANUFACTURER
|
#ifndef GATEWAY_MANUFACTURER
|
||||||
# define GATEWAY_MANUFACTURER "OMG_community"
|
# define GATEWAY_MANUFACTURER "OMG_community"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ int failure_number_ntwk = 0; // number of failure connecting to network
|
|||||||
int failure_number_mqtt = 0; // number of failure connecting to MQTT
|
int failure_number_mqtt = 0; // number of failure connecting to MQTT
|
||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
bool disc = true; // Auto discovery with Home Assistant convention
|
bool disc = true; // Auto discovery with Home Assistant convention
|
||||||
|
unsigned long lastDiscovery = 0; // Time of the last discovery to trigger automaticaly to off after DiscoveryAutoOffTimer
|
||||||
#endif
|
#endif
|
||||||
unsigned long timer_led_measures = 0;
|
unsigned long timer_led_measures = 0;
|
||||||
static void* eClient = nullptr;
|
static void* eClient = nullptr;
|
||||||
@@ -1537,6 +1538,9 @@ void loop() {
|
|||||||
bool justReconnected = !connected;
|
bool justReconnected = !connected;
|
||||||
|
|
||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
|
// Deactivate autodiscovery after DiscoveryAutoOffTimer
|
||||||
|
if (disc && (now > lastDiscovery + DiscoveryAutoOffTimer))
|
||||||
|
disc = false;
|
||||||
// at first connection we publish the discovery payloads
|
// at first connection we publish the discovery payloads
|
||||||
// or, when we have just re-connected (only when discovery_republish_on_reconnect is enabled)
|
// or, when we have just re-connected (only when discovery_republish_on_reconnect is enabled)
|
||||||
bool publishDiscovery = disc && (!connectedOnce || (discovery_republish_on_reconnect && justReconnected));
|
bool publishDiscovery = disc && (!connectedOnce || (discovery_republish_on_reconnect && justReconnected));
|
||||||
@@ -2363,6 +2367,8 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
if (SYSdata.containsKey("discovery")) {
|
if (SYSdata.containsKey("discovery")) {
|
||||||
if (SYSdata["discovery"].is<bool>()) {
|
if (SYSdata["discovery"].is<bool>()) {
|
||||||
|
if (SYSdata["discovery"] == true && disc == false)
|
||||||
|
lastDiscovery = millis();
|
||||||
disc = SYSdata["discovery"];
|
disc = SYSdata["discovery"];
|
||||||
stateMeasures();
|
stateMeasures();
|
||||||
if (disc)
|
if (disc)
|
||||||
|
|||||||
Reference in new issue
Block a user