From e26fd9f132dfa05b6a47a265ce7087e02bd97701 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Mon, 8 Sep 2025 04:01:16 +0200 Subject: [PATCH] fix: Front door presence does not get cleared properly --- automation_lib/src/mqtt.rs | 8 +++++++- config.lua | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/automation_lib/src/mqtt.rs b/automation_lib/src/mqtt.rs index 7e71d43..fc19fba 100644 --- a/automation_lib/src/mqtt.rs +++ b/automation_lib/src/mqtt.rs @@ -28,7 +28,13 @@ impl mlua::UserData for WrappedAsyncClient { methods.add_async_method( "send_message", async |_lua, this, (topic, message): (String, mlua::Value)| { - let message = serde_json::to_string(&message).unwrap(); + // serde_json converts nil => "null", but we actually want nil to send an empty + // message + let message = if message.is_nil() { + "".into() + } else { + serde_json::to_string(&message).unwrap() + }; debug!("message = {message}"); diff --git a/config.lua b/config.lua index 419a6b7..06a54fc 100644 --- a/config.lua +++ b/config.lua @@ -520,7 +520,7 @@ setmetatable(frontdoor_presence, { end else self.timeout:start(debug and 10 or 15 * 60, function() - mqtt_client:send_message(mqtt_automation("presence/contact/frontdoor"), {}) + mqtt_client:send_message(mqtt_automation("presence/contact/frontdoor"), nil) end) end end,