From 03eba4108410c5dd7063f07f4d5e0571c5e8916c Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Tue, 11 Jun 2019 21:44:20 +0200 Subject: [PATCH] Integrate cleargrass temp and humidity indoor sensor ESP32, HM10 and discovery with HASS --- ZgatewayBT.ino | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/ZgatewayBT.ino b/ZgatewayBT.ino index 3daf775..b15e603 100644 --- a/ZgatewayBT.ino +++ b/ZgatewayBT.ino @@ -104,6 +104,7 @@ vector devices; pos = strpos(service_data,"209800"); if (pos != -1){ trc(F("mi flora data reading")); + //example "servicedata":"71209800bc63b6658d7cc40d0910023200" #ifdef ZmqttDiscovery if(!isDiscovered(mac)) MiFloraDiscovery(mac); #endif @@ -122,12 +123,22 @@ vector devices; pos = strpos(service_data,"205b04"); if (pos != -1){ trc(F("LYWSD02 data reading")); - //example 70205b04b96ab883c8593f09041002e000 + //example "servicedata":"70205b04b96ab883c8593f09041002e000" #ifdef ZmqttDiscovery if(!isDiscovered(mac)) LYWSD02Discovery(mac); #endif process_data(pos - 24,service_data,mac); } + pos = -1; + pos = strpos(service_data,"304703"); + if (pos != -1){ + trc(F("ClearGrass T RH data reading")); + //example "servicedata":"5030470340743e10342d58041002d6000a100164" + #ifdef ZmqttDiscovery + if(!isDiscovered(mac)) CLEARGRASSTRHDiscovery(mac); + #endif + process_data(pos - 26,service_data,mac); + } } } } @@ -322,6 +333,15 @@ vector devices; #endif boolean result = process_data(pos - 38,(char *)Service_data.c_str(),d[0].extract); } + pos = -1; + pos = strpos(d[5].extract,"304703"); + if (pos != -1){ + trc("CLEARGRASSTRH data reading"); + #ifdef ZmqttDiscovery + if(!isDiscovered(d[0].extract)) CLEARGRASSTRHDiscovery(d[0].extract); + #endif + boolean result = process_data(pos - 40,(char *)Service_data.c_str(),d[0].extract); + } return true; } } @@ -428,6 +448,33 @@ void LYWSD02Discovery(char * mac){ devices.push_back(device); } +void CLEARGRASSTRHDiscovery(char * mac){ + #define CLEARGRASSTRHparametersCount 3 + trc(F("CLEARGRASSTRHDiscovery")); + char * CLEARGRASSTRHsensor[CLEARGRASSTRHparametersCount][8] = { + {"sensor", "CLEARGRASSTRH-batt", mac, "battery","{{ value_json.batt | is_defined }}","", "", "V"} , + {"sensor", "CLEARGRASSTRH-tem", mac,"temperature","{{ value_json.tem | is_defined }}","", "", "°C"} , + {"sensor", "CLEARGRASSTRH-hum", mac,"humidity","{{ value_json.hum | is_defined }}","", "", "%"} + //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement + }; + + for (int i=0;i