Skip to content

Commit

Permalink
Add status binary sensor and text sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
1technophile committed Nov 13, 2023
1 parent a692cee commit 86fbf23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +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) {
} 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(),
Expand Down
5 changes: 4 additions & 1 deletion main/config_mqttDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ void announceDeviceTrigger(bool use_gateway_info,
const char* availableHASSClasses[] = {"battery",
"carbon_monoxide",
"carbon_dioxide",
"door",
"enum",
"pm10",
"pm25",
"humidity",
Expand All @@ -197,7 +199,8 @@ 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
Expand Down

0 comments on commit 86fbf23

Please sign in to comment.