Presence and light sensor call all function in array
This commit is contained in:
56
config.lua
56
config.lua
@@ -34,11 +34,24 @@ local ntfy = Ntfy.new({
|
|||||||
})
|
})
|
||||||
automation.device_manager:add(ntfy)
|
automation.device_manager:add(ntfy)
|
||||||
|
|
||||||
|
local on_presence = {
|
||||||
|
add = function(self, f)
|
||||||
|
self[#self + 1] = f
|
||||||
|
end,
|
||||||
|
}
|
||||||
automation.device_manager:add(Presence.new({
|
automation.device_manager:add(Presence.new({
|
||||||
topic = mqtt_automation("presence/+/#"),
|
topic = mqtt_automation("presence/+/#"),
|
||||||
client = mqtt_client,
|
client = mqtt_client,
|
||||||
event_channel = automation.device_manager:event_channel(),
|
event_channel = automation.device_manager:event_channel(),
|
||||||
callback = function(_, presence)
|
callback = function(_, presence)
|
||||||
|
for _, f in ipairs(on_presence) do
|
||||||
|
if type(f) == "function" then
|
||||||
|
f(presence)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}))
|
||||||
|
on_presence:add(function(presence)
|
||||||
ntfy:send_notification({
|
ntfy:send_notification({
|
||||||
title = "Presence",
|
title = "Presence",
|
||||||
message = presence and "Home" or "Away",
|
message = presence and "Home" or "Away",
|
||||||
@@ -56,8 +69,33 @@ automation.device_manager:add(Presence.new({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
|
local on_light = {
|
||||||
|
add = function(self, f)
|
||||||
|
self[#self + 1] = f
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
automation.device_manager:add(LightSensor.new({
|
||||||
|
identifier = "living_light_sensor",
|
||||||
|
topic = mqtt_z2m("living/light"),
|
||||||
|
client = mqtt_client,
|
||||||
|
min = 22000,
|
||||||
|
max = 23500,
|
||||||
|
callback = function(_, light)
|
||||||
|
for _, f in ipairs(on_light) do
|
||||||
|
if type(f) == "function" then
|
||||||
|
f(light)
|
||||||
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
}))
|
}))
|
||||||
|
on_light:add(function(light)
|
||||||
|
mqtt_client:send_message(mqtt_automation("debug") .. "/darkness", {
|
||||||
|
state = not light,
|
||||||
|
updated = automation.util.get_epoch(),
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
automation.device_manager:add(DebugBridge.new({
|
automation.device_manager:add(DebugBridge.new({
|
||||||
identifier = "debug_bridge",
|
identifier = "debug_bridge",
|
||||||
@@ -78,6 +116,9 @@ local hue_bridge = HueBridge.new({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
automation.device_manager:add(hue_bridge)
|
automation.device_manager:add(hue_bridge)
|
||||||
|
on_light:add(function(light)
|
||||||
|
hue_bridge:set_flag("darkness", not light)
|
||||||
|
end)
|
||||||
|
|
||||||
local kitchen_lights = HueGroup.new({
|
local kitchen_lights = HueGroup.new({
|
||||||
identifier = "kitchen_lights",
|
identifier = "kitchen_lights",
|
||||||
@@ -120,21 +161,6 @@ automation.device_manager:add(HueSwitch.new({
|
|||||||
end,
|
end,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
automation.device_manager:add(LightSensor.new({
|
|
||||||
identifier = "living_light_sensor",
|
|
||||||
topic = mqtt_z2m("living/light"),
|
|
||||||
client = mqtt_client,
|
|
||||||
min = 22000,
|
|
||||||
max = 23500,
|
|
||||||
callback = function(_, light)
|
|
||||||
hue_bridge:set_flag("darkness", not light)
|
|
||||||
mqtt_client:send_message(mqtt_automation("debug") .. "/darkness", {
|
|
||||||
state = not light,
|
|
||||||
updated = automation.util.get_epoch(),
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
}))
|
|
||||||
|
|
||||||
automation.device_manager:add(WakeOnLAN.new({
|
automation.device_manager:add(WakeOnLAN.new({
|
||||||
name = "Zeus",
|
name = "Zeus",
|
||||||
room = "Living Room",
|
room = "Living Room",
|
||||||
|
|||||||
Reference in New Issue
Block a user