[BT] Fix HA discovery for motion and door sensor (#1798)
* [BT] Fix HA discovery for motion sensor * Add status binary sensor and text sensor
This commit is contained in:
1 parent
5a36034a2f
commit
e576b26b8c
4 files changed
+32
-2
No files matched your search
@@ -68,6 +68,10 @@ Note that you can find apps to simulate beacons and do some tests like [Beacon s
|
||||
|
||||
iOS version >=10 devices advertise without an extra app MAC address, nevertheless this address [changes randomly](https://github.com/1technophile/OpenMQTTGateway/issues/71) and cannot be used for presence detection. You must install an app to advertise a fixed MAC address.
|
||||
|
||||
::: info
|
||||
The `presenceawaytimer` is also used to reset the state of the PIR/motion sensors to `off` when using HA MQTT discovery convention. If the Sensor does not detect a motion, its state will be automatically set to `off` after the `presenceawaytimer`.
|
||||
:::
|
||||
|
||||
## Receiving signals from BLE devices with accelerometers for movement detection
|
||||
The gateway is designed to detect BLE trackers from BlueCharm and automatically create a binary sensor entity in accordance with the Home Assistant discovery convention, provided that auto discovery is enabled.
|
||||
|
||||
|
||||
@@ -1030,6 +1030,30 @@ void launchBTDiscovery(bool overrideDiscovery) {
|
||||
0, "", "", false, "",
|
||||
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
|
||||
stateClassMeasurement, nullptr, nullptr, "[\"lb\",\"kg\",\"jin\"]");
|
||||
} else if (strcmp(prop.key().c_str(), "pres") == 0 || strcmp(prop.key().c_str(), "movement") == 0) {
|
||||
createDiscovery("binary_sensor",
|
||||
discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(),
|
||||
will_Topic, "motion", value_template.c_str(), // Idealy we should have the decoder give the name here as "motion" but for now it gives "presence"
|
||||
"True", "False", "",
|
||||
BTConfig.presenceAwayTimer, "", "", false, "",
|
||||
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
|
||||
stateClassNone);
|
||||
} else if (strcmp(prop.value()["unit"], "string") == 0 && strcmp(prop.key().c_str(), "mac") != 0) {
|
||||
createDiscovery("sensor",
|
||||
discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(),
|
||||
will_Topic, prop.value()["name"], value_template.c_str(),
|
||||
"", "", "",
|
||||
0, "", "", false, "",
|
||||
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
|
||||
stateClassNone);
|
||||
} else if (strcmp(prop.value()["unit"], "status") == 0) {
|
||||
createDiscovery("binary_sensor",
|
||||
discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(),
|
||||
will_Topic, prop.value()["name"], value_template.c_str(),
|
||||
"True", "False", "",
|
||||
0, "", "", false, "",
|
||||
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
|
||||
stateClassNone);
|
||||
} else if (strcmp(prop.key().c_str(), "device") != 0 && strcmp(prop.key().c_str(), "mac") != 0) { // Exception on device and mac as these ones are not sensors
|
||||
createDiscovery("sensor",
|
||||
discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(),
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ struct BTConfig_s {
|
||||
bool pubAdvData; // Publish advertisement data
|
||||
bool pubBeaconUuidForTopic; // Use iBeacon UUID as topic, instead of sender (random) MAC address
|
||||
bool ignoreWBlist; // Disable Whitelist & Blacklist
|
||||
unsigned long presenceAwayTimer; //Timer that trigger a tracker state as offline if not seen
|
||||
unsigned long presenceAwayTimer; //Timer that trigger a tracker/PIR state as offline/off if not seen
|
||||
unsigned long movingTimer; //Timer that trigger a moving sensor state as offline if not seen
|
||||
};
|
||||
|
||||
|
||||
@@ -184,6 +184,8 @@ void announceDeviceTrigger(bool use_gateway_info,
|
||||
const char* availableHASSClasses[] = {"battery",
|
||||
"carbon_monoxide",
|
||||
"carbon_dioxide",
|
||||
"door",
|
||||
"enum",
|
||||
"pm10",
|
||||
"pm25",
|
||||
"humidity",
|
||||
@@ -197,7 +199,7 @@ const char* availableHASSClasses[] = {"battery",
|
||||
"energy",
|
||||
"power_factor",
|
||||
"voltage",
|
||||
"enum"};
|
||||
"window"};
|
||||
|
||||
// From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L379
|
||||
// List of units available in Home Assistant
|
||||
|
||||
Reference in new issue
Block a user