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

Introduces standardized key for govee binary moisture sensors #2625

Merged
merged 1 commit into from
Sep 27, 2023
Merged
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
21 changes: 21 additions & 0 deletions src/devices/govee.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,21 @@ static int govee_decode(r_device *decoder, bitbuffer_t *bitbuffer)
event &= 0x0FFF;

char const *event_str;
int wet = -1;
// Figure out what event was triggered
if (event == 0xafa) {
event_str = "Button Press";
// The H5054 water sensor does not send a message when it transitions from wet to dry nor does it have a
// dedicated message to indicate that it is not wet. However, the sensor only sends a "button press" message if
// the button is pressed while the device is dry (no button press message is sent if the button is pressed while
// the sensor is wet). Since we know the sensor is dry when a "button press" message is received, "detect_wet:0"
// is included in the output when the button is pressed as a workaround to allow the user to transition the
// device back to the dry state.
wet = 0;
}
else if (event == 0xbfb) {
event_str = "Water Leak";
wet = 1;
}
else if (event_type == 0xc) {
event_str = "Battery Report";
Expand All @@ -227,6 +236,7 @@ static int govee_decode(r_device *decoder, bitbuffer_t *bitbuffer)
"id" , "", DATA_INT, id,
"battery_ok", "Battery level", DATA_COND, battery, DATA_DOUBLE, battery_level,
"battery_mV", "Battery", DATA_COND, battery, DATA_FORMAT, "%d mV", DATA_INT, battery_mv,
"detect_wet", "", DATA_COND, wet >= 0, DATA_INT, wet,
"event", "", DATA_STRING, event_str,
"code", "Raw Code", DATA_STRING, code_str,
"mic", "Integrity", DATA_STRING, "PARITY",
Expand All @@ -243,6 +253,7 @@ static char const *const output_fields[] = {
"id",
"battery_ok",
"battery_mV",
"detect_wet",
"event",
"code",
"mic",
Expand Down Expand Up @@ -349,18 +360,27 @@ static int govee_h5054_decode(r_device *decoder, bitbuffer_t *bitbuffer)
decoder_logf(decoder, 1, __func__, "crc_sum=%04x", crc_sum);

char const *event_str;
int wet = -1;
int leak_num = -1;
int battery = -1;
switch (event) {
case 0x0:
event_str = "Button Press";
// The H5054 water sensor does not send a message when it transitions from wet to dry nor does it have a
// dedicated message to indicate that it is not wet. However, the sensor only sends a "button press" message if
// the button is pressed while the device is dry (no button press message is sent if the button is pressed while
// the sensor is wet). Since we know the sensor is dry when a "button press" message is received, "detect_wet:0"
// is included in the output when the button is pressed as a workaround to allow the user to transition the
// device back to the dry state.
wet = 0;
break;
case 0x1:
event_str = "Battery Report";
battery = event_data;
break;
case 0x2:
event_str = "Water Leak";
wet = 1;
leak_num = event_data;
break;
default:
Expand All @@ -378,6 +398,7 @@ static int govee_h5054_decode(r_device *decoder, bitbuffer_t *bitbuffer)
"battery_ok", "Battery level", DATA_COND, battery >= 0, DATA_DOUBLE, battery_level,
"battery_mV", "Battery", DATA_COND, battery >= 0, DATA_FORMAT, "%d mV", DATA_INT, battery_mv,
"event", "", DATA_STRING, event_str,
"detect_wet", "", DATA_COND, wet >= 0, DATA_INT, wet,
"leak_num", "Leak Num", DATA_COND, leak_num >= 0, DATA_INT, leak_num,
"code", "Raw Code", DATA_STRING, code_str,
"mic", "Integrity", DATA_STRING, "CRC",
Expand Down
Loading