Files
automation_rs/config/windows.lua
Dreaded_X 1766a7b175
All checks were successful
Build and deploy / build (push) Successful in 10m15s
Build and deploy / Deploy container (push) Has been skipped
WIP
2025-10-19 07:21:57 +02:00

44 lines
840 B
Lua

local presence = require("config.presence")
local ntfy = require("config.ntfy")
local module = {}
--- @class OnPresence
--- @field [integer] OpenCloseInterface
local sensors = {}
--- @param sensor OpenCloseInterface
function module.add(sensor)
table.insert(sensors, sensor)
end
function module.setup()
presence.add_callback(function(p)
if not p then
local open = {}
for _, sensor in ipairs(sensors) do
if sensor:open_percent() > 0 then
local id = sensor:get_id()
print("Open window detected: " .. id)
table.insert(open, id)
end
end
if #open > 0 then
local message = table.concat(open, "\n")
ntfy.device:send_notification({
title = "Windows are open",
message = message,
tags = { "window" },
priority = "high",
})
end
end
end)
return {}
end
return module