Skip to content

Commit 9c2adca

Browse files
bafultonclaudeDigiH
authored
Add Govee H5140 Smart CO2 Monitor (#684)
* Add Govee H5140 Smart CO2 Monitor decoder Adds support for the Govee H5140 Smart CO2 Monitor, which broadcasts temperature, humidity, and CO2 readings via BLE manufacturer data. Device identification: - Advertisement name pattern: GV5140XXXX - Manufacturer data: 20 hex characters (10 bytes) Data format (hex positions): - 0-7: Header (01000101) - 8-13: 24-bit combined temp/humidity value - 14-17: 16-bit CO2 in ppm (big-endian) - 18-19: Padding Decoding: - Temperature (°C): 24bit_value / 10000 - Humidity (%): (24bit_value % 1000) / 10 - CO2 (ppm): 16bit_value directly Tested with device GV5140A2D6 (MAC: 3C:DC:75:13:A2:D6) via OpenMQTTGateway on ESP32. * Fix H5140 condition to check manufacturer data header Add compound condition to verify: - Device name contains 'GV5140' - Manufacturer data length >= 20 hex chars - Manufacturer data starts with '01000101' header This prevents false matches against other devices' data. * Add H5140 to BLE_ID_NUM enum The enum must match the order of entries in the devices array. * Address review feedback for H5140 decoder - Change tag from 0301 to 0f02 (AIR sensor classification) - Rename co2 property to carbon_dioxide for HA MQTT discovery - Add documentation page 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add regression test cases for H5140 decoder 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix test expected output - remove cidc field H5140 uses a device-specific header (01000101) like H5179_N, not the standard Govee company ID (88ec). Since there's no company ID check in the condition, the decoder output doesn't include cidc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * tag correction * test adjustment for tag correction --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: DigiH <17110652+DigiH@users.noreply.github.com>
1 parent 1475252 commit 9c2adca

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

docs/devices/H5140.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Govee H5140
2+
3+
|Model Id|[H5140](https://github.com/theengs/decoder/blob/development/src/devices/H5140_json.h)|
4+
|-|-|
5+
|Brand|Govee|
6+
|Model|Smart CO2 Monitor|
7+
|Short Description|Air quality monitor with temperature, humidity and CO2|
8+
|Communication|BLE broadcast|
9+
|Frequency|2.4Ghz|
10+
|Power Source|USB-C|
11+
|Exchanged Data|temperature, humidity, CO2|
12+
|Encrypted|No|

src/decoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class TheengsDecoder {
9292
H5074,
9393
H5102,
9494
H5106,
95+
H5140,
9596
H5179,
9697
H5179_N,
9798
HHCCJCY10,

src/devices.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "devices/H5074_json.h"
3737
#include "devices/H5102_json.h"
3838
#include "devices/H5106_json.h"
39+
#include "devices/H5140_json.h"
3940
#include "devices/H5179_json.h"
4041
#include "devices/HHCCJCY10_json.h"
4142
#include "devices/HHCCJCY01HHCC_json.h"
@@ -188,6 +189,7 @@ const char* _devices[][2] = {
188189
{_H5074_json, _H5074_json_props},
189190
{_H5102_json, _H5102_json_props},
190191
{_H5106_json, _H5106_json_props},
192+
{_H5140_json, _H5140_json_props},
191193
{_H5179_json, _H5179_json_props},
192194
{_H5179_json_N, _H5179_json_props},
193195
{_HHCCJCY10_json, _HHCCJCY10_json_props},

src/devices/H5140_json.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const char* _H5140_json = "{\"brand\":\"Govee\",\"model\":\"Smart CO2 Monitor\",\"model_id\":\"H5140\",\"tag\":\"0f03\",\"condition\":[\"name\",\"contain\",\"GV5140\",\"&\",\"manufacturerdata\",\">=\",20,\"index\",0,\"01000101\"],\"properties\":{\"tempc\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",8,6,false,false],\"post_proc\":[\"/\",10000]},\"hum\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",8,6,false,false],\"post_proc\":[\"&\",2147483647,\"%\",1000,\"/\",10]},\"co2\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",14,4,false,false]}}}";
2+
/* R""""(
3+
{
4+
"brand":"Govee",
5+
"model":"Smart CO2 Monitor",
6+
"model_id":"H5140",
7+
"tag":"0f03",
8+
"condition":["name", "contain", "GV5140", "&", "manufacturerdata", ">=", 20, "index", 0, "01000101"],
9+
"properties":{
10+
"tempc":{
11+
"decoder":["value_from_hex_data", "manufacturerdata", 8, 6, false, false],
12+
"post_proc":["/", 10000]
13+
},
14+
"hum":{
15+
"decoder":["value_from_hex_data", "manufacturerdata", 8, 6, false, false],
16+
"post_proc":["&", 2147483647, "%", 1000, "/", 10]
17+
},
18+
"co2":{
19+
"decoder":["value_from_hex_data", "manufacturerdata", 14, 4, false, false]
20+
}
21+
}
22+
})"""";*/
23+
24+
/*
25+
* Govee H5140 Smart CO2 Monitor - BLE Manufacturer Data Format
26+
* =============================================================
27+
*
28+
* Advertisement name pattern: GV5140XXXX (where XXXX is device suffix)
29+
* Manufacturer data: 20 hex characters (10 bytes)
30+
*
31+
* Byte layout:
32+
* Positions 0-7: 01000101 (constant header)
33+
* Positions 8-13: XXXXXX (24-bit combined temp/humidity)
34+
* Positions 14-17: YYYY (16-bit CO2 in ppm, big-endian)
35+
* Positions 18-19: 00 (padding/unknown)
36+
*
37+
* Decoding formulas:
38+
* - temp_celsius = 24bit_value / 10000
39+
* - humidity_percent = (24bit_value % 1000) / 10
40+
* - co2_ppm = 16bit_value
41+
*
42+
* Example: 0100010103fcbf044c00
43+
* - Header: 01000101
44+
* - Temp/Hum: 03fcbf = 261311 decimal
45+
* - Temperature: 261311 / 10000 = 26.13°C (79.04°F)
46+
* - Humidity: (261311 % 1000) / 10 = 31.1%
47+
* - CO2: 044c = 1100 ppm
48+
*
49+
* Tested with OpenMQTTGateway on ESP32
50+
*/
51+
52+
const char* _H5140_json_props = "{\"properties\":{\"tempc\":{\"unit\":\"°C\",\"name\":\"temperature\"},\"hum\":{\"unit\":\"%\",\"name\":\"humidity\"},\"co2\":{\"unit\":\"ppm\",\"name\":\"carbon_dioxide\"}}}";
53+
/*R""""(
54+
{
55+
"properties":{
56+
"tempc":{
57+
"unit":"°C",
58+
"name":"temperature"
59+
},
60+
"hum":{
61+
"unit":"%",
62+
"name":"humidity"
63+
},
64+
"co2":{
65+
"unit":"ppm",
66+
"name":"carbon_dioxide"
67+
}
68+
}
69+
})"""";*/

tests/BLE/test_ble.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ const char* expected_mfg[] = {
237237
"{\"brand\":\"Victron Energy\",\"model\":\"Smart Battery Sense\",\"model_id\":\"VICTSBS\",\"type\":\"ENRG\",\"track\":true,\"volt\":12.99,\"tempc\":17.5,\"tempf\":63.5,\"alarm_reason\":0}",
238238
"{\"brand\":\"Victron Energy\",\"model\":\"Smart Battery Sense\",\"model_id\":\"VICTSBS\",\"type\":\"ENRG\",\"track\":true,\"volt\":14.01,\"tempc\":17.5,\"tempf\":63.5,\"alarm_reason\":0}",
239239
"{\"brand\":\"Victron Energy\",\"model\":\"Smart Battery Sense\",\"model_id\":\"VICTSBS\",\"type\":\"ENRG\",\"track\":true,\"volt\":12.22,\"tempc\":22.5,\"tempf\":72.5,\"alarm_reason\":0}",
240+
"{\"brand\":\"Govee\",\"model\":\"Smart CO2 Monitor\",\"model_id\":\"H5140\",\"type\":\"AIR\",\"cidc\":false,\"acts\":true,\"tempc\":26.1311,\"tempf\":79.03598,\"hum\":31.1,\"co2\":1100}",
241+
"{\"brand\":\"Govee\",\"model\":\"Smart CO2 Monitor\",\"model_id\":\"H5140\",\"type\":\"AIR\",\"cidc\":false,\"acts\":true,\"tempc\":15.56,\"tempf\":60.008,\"hum\":60,\"co2\":500}",
242+
"{\"brand\":\"Govee\",\"model\":\"Smart CO2 Monitor\",\"model_id\":\"H5140\",\"type\":\"AIR\",\"cidc\":false,\"acts\":true,\"tempc\":23.8048,\"tempf\":74.84864,\"hum\":4.8,\"co2\":1700}",
240243
};
241244

242245
const char* expected_name_uuid_mfgsvcdata[] = {
@@ -828,6 +831,9 @@ const char* test_mfgdata[][3] = {
828831
{"Victron Smart Battery Sense", "", "e1021180a5a302ffff7bffff130500008971feff7fffffffff"},
829832
{"Victron Smart Battery Sense", "", "e1021180a5a302ffff7bffff790500008971feff7fffffffff"},
830833
{"Victron Smart Battery Sense", "", "e1021100a4a302ffff7cffffc60400007d73feff7fffffffff"},
834+
{"H5140", "GV5140_1234", "0100010103fcbf044c00"},
835+
{"H5140", "GV5140_1234", "01000101025fd001f400"},
836+
{"H5140", "GV5140_1234", "0100010103a1e006a400"},
831837
};
832838

833839
TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
@@ -1048,6 +1054,9 @@ TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
10481054
TheengsDecoder::BLE_ID_NUM::VICTSBS,
10491055
TheengsDecoder::BLE_ID_NUM::VICTSBS,
10501056
TheengsDecoder::BLE_ID_NUM::VICTSBS,
1057+
TheengsDecoder::BLE_ID_NUM::H5140,
1058+
TheengsDecoder::BLE_ID_NUM::H5140,
1059+
TheengsDecoder::BLE_ID_NUM::H5140,
10511060
};
10521061

10531062
// uuid test input [test name] [device name] [uuid] [manufacturer data] [service data]

0 commit comments

Comments
 (0)