Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discovery with theengs decoder #1106

Merged
merged 3 commits into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/prerequisites/devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ Added to that it retrieves the measures from the devices below. By default the d
| XIAOMI Mi Jia 2 custom firmware (3)|LYWSD03MMC PVVX|temperature/humidity/battery/volt|
| XIAOMI MHO-C401 (1)(c)|MHO-C401|temperature/humidity/battery/volt|
| XIAOMI Mi Lamp |MUE4094RT|presence|
| GOVEE |H5075|temperature/humidity/battery|
| GOVEE |H5072|temperature/humidity/battery|
| HONEYWELL |JQJCY01YM|formaldehyde/temperature/humidity/battery|
| INKBIRD (1)|IBS-TH1|temperature/humidity/battery|
| INKBIRD (1)|IBS-TH2|temperature/battery|
| INKBIRD (1)|IBT-4XS|temperature1/temperature2/temperature3/temperature4|
| INKBIRD (1)|IBT-2X|temperature1/temperature2|
| ClearGrass |CGG1|temperature/humidity/battery|
| Qingping |CGDK2|temperature/humidity|
| Qingping |CGH1|open|
Expand Down
8 changes: 4 additions & 4 deletions main/ZactuatorPWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
JsonVariant value = jsonData[channelJsonKeys[i]];
if (!value.isNull()) {
float targetValue = value.as<float>();
targetValue = min(targetValue, 1.f);
targetValue = max(targetValue, 0.f);
targetValue = std::min(targetValue, 1.f);
targetValue = std::max(targetValue, 0.f);
targetValues[i] = targetValue;

// Initially configure as an instantaneous change....
Expand Down Expand Up @@ -239,8 +239,8 @@ void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
if (!value.isNull()) {
float gamma = value.as<float>();
// Sanity check
gamma = min(gamma, 4.f);
gamma = max(gamma, 0.5f);
gamma = std::min(gamma, 4.f);
gamma = std::max(gamma, 0.5f);
calibrationGamma[i] = gamma;
}
snprintf(key, sizeof(key), "min-%s", channelJsonKeys[i]);
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewayBLEConnect.ino
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ void LYWSD03MMC_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pD
for (std::vector<BLEdevice*>::iterator it = devices.begin(); it != devices.end(); ++it) {
BLEdevice* p = *it;
if ((strcmp(p->macAdr, (char*)mac_address.c_str()) == 0)) {
if (p->sensorModel == LYWSD03MMC)
if (p->sensorModel_id.compare("LYWSD03MMC") == 0)
BLEdata["model"] = "LYWSD03MMC";
else if (p->sensorModel == MHO_C401)
else if (p->sensorModel_id.compare("MHO_C401") == 0)
BLEdata["model"] = "MHO_C401";
}
}
Expand Down
477 changes: 102 additions & 375 deletions main/ZgatewayBT.ino

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions main/ZmqttDiscovery.ino
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ void createDiscoveryFromList(const char* mac,
*/
void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char* subtype, char* unique_id, char* device_name, char* device_manufacturer, char* device_model, char* device_mac) {
//Create The Json
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(14) + JSON_OBJECT_SIZE(5) + JSON_ARRAY_SIZE(1);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject sensor = jsonBuffer.to<JsonObject>();

// SET Default Configuration
Expand Down Expand Up @@ -223,8 +222,7 @@ void createDiscovery(const char* sensor_type,
const char* payload_available, const char* payload_not_avalaible, bool gateway_entity, const char* cmd_topic,
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_mac, bool retainCmd,
const char* state_class) {
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(14) + JSON_OBJECT_SIZE(5) + JSON_ARRAY_SIZE(1);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject sensor = jsonBuffer.to<JsonObject>();

// If a component cannot render it's state (f.i. KAKU relays) no state topic
Expand Down
38 changes: 1 addition & 37 deletions main/config_BT.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,6 @@ bool hassPresence = HassPresence;
/*-------------------HOME ASSISTANT ROOM PRESENCE ----------------------*/
#define subjectHomePresence "home_presence/" // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name)

enum ble_sensor_model {
UNKNOWN_MODEL = -1,
BEGINING = 0,
HHCCJCY01HHCC,
VEGTRUG,
LYWSDCGQ,
JQJCY01YM,
LYWSD02, //5
CGG1,
CGP1W,
MUE4094RT,
CGD1,
MIBAND, //10
XMTZC04HM,
XMTZC05HM,
IBSTH1,
LYWSD03MMC,
MHO_C401, //15
LYWSD03MMC_ATC,
INODE_EM,
CGDK2,
LYWSD03MMC_PVVX,
CGH1, //20
CGPR1,
WS02,
IBSTH2,
IBT4XS,
DT24, //25
EDDYSTONE_TLM,
MOKOBEACON,
MOKOBEACONXPRO,
IBEACON,
TPMS,
GENERIC,
};

/*-------------------PIN DEFINITIONS----------------------*/
#if !defined(BT_RX) || !defined(BT_TX)
# ifdef ESP8266
Expand Down Expand Up @@ -204,7 +168,7 @@ struct BLEdevice {
bool isWhtL;
bool isBlkL;
bool connect;
ble_sensor_model sensorModel;
std::string sensorModel_id;
};

JsonObject& getBTJsonObject(const char* json = NULL, bool haPresenceEnabled = true);
Expand Down
5 changes: 4 additions & 1 deletion main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ ReceivedSignal receivedSignal[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
//Time used to wait for an interval before checking system measures
unsigned long timer_sys_measures = 0;
# define ARDUINOJSON_USE_LONG_LONG 1
# define ARDUINOJSON_USE_LONG_LONG 1
# define ARDUINOJSON_ENABLE_STD_STRING 1
#endif

#include <ArduinoJson.h>
#include <ArduinoLog.h>
#include <PubSubClient.h>

#include <string>

StaticJsonDocument<JSON_MSG_BUFFER> modulesBuffer;
JsonArray modules = modulesBuffer.to<JsonArray>();

Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ somfy_remote=Somfy_Remote_Lib@0.3.0
rtl_433_ESP = https://github.com/NorthernMan54/rtl_433_ESP#e03f689
emodbus = miq19/eModbus@1.0.0
gfSunInverter = https://github.com/BlackSmith/GFSunInverter.git#v1.0.1
decoder = https://github.com/theengs/decoder.git#v0.1.2
decoder = https://github.com/theengs/decoder.git#v0.1.3

[env]
framework = arduino
Expand Down