refactor: Split config
This commit is contained in:
39
config/rooms/bathroom.lua
Normal file
39
config/rooms/bathroom.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
local debug = require("config.debug")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local ntfy = require("config.ntfy")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local light = devices.LightOnOff.new({
|
||||
name = "Light",
|
||||
room = "Bathroom",
|
||||
topic = helper.mqtt_z2m("bathroom/light"),
|
||||
client = mqtt_client,
|
||||
callback = helper.off_timeout(debug.debug_mode and 60 or 45 * 60),
|
||||
})
|
||||
|
||||
local washer = devices.Washer.new({
|
||||
identifier = "bathroom_washer",
|
||||
topic = helper.mqtt_z2m("bathroom/washer"),
|
||||
client = mqtt_client,
|
||||
threshold = 1,
|
||||
done_callback = function()
|
||||
ntfy.send_notification({
|
||||
title = "Laundy is done",
|
||||
message = "Don't forget to hang it!",
|
||||
tags = { "womans_clothes" },
|
||||
priority = "high",
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
return {
|
||||
light,
|
||||
washer,
|
||||
}
|
||||
end
|
||||
|
||||
return module
|
||||
74
config/rooms/bedroom.lua
Normal file
74
config/rooms/bedroom.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
local battery = require("config.battery")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local hue_bridge = require("config.hue_bridge")
|
||||
local windows = require("config.windows")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type AirFilter?
|
||||
local air_filter = nil
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local lights = devices.HueGroup.new({
|
||||
identifier = "bedroom_lights",
|
||||
ip = hue_bridge.ip,
|
||||
login = hue_bridge.token,
|
||||
group_id = 3,
|
||||
scene_id = "PvRs-lGD4VRytL9",
|
||||
})
|
||||
local lights_relax = devices.HueGroup.new({
|
||||
identifier = "bedroom_lights_relax",
|
||||
ip = hue_bridge.ip,
|
||||
login = hue_bridge.token,
|
||||
group_id = 3,
|
||||
scene_id = "60tfTyR168v2csz",
|
||||
})
|
||||
|
||||
air_filter = devices.AirFilter.new({
|
||||
name = "Air Filter",
|
||||
room = "Bedroom",
|
||||
url = "http://10.0.0.103",
|
||||
})
|
||||
|
||||
local switch = devices.HueSwitch.new({
|
||||
name = "Switch",
|
||||
room = "Bedroom",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("bedroom/switch"),
|
||||
left_callback = function()
|
||||
lights:set_on(not lights:on())
|
||||
end,
|
||||
left_hold_callback = function()
|
||||
lights_relax:set_on(true)
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
local window = devices.ContactSensor.new({
|
||||
name = "Window",
|
||||
room = "Bedroom",
|
||||
topic = helper.mqtt_z2m("bedroom/window"),
|
||||
client = mqtt_client,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
windows.add(window)
|
||||
|
||||
return {
|
||||
lights,
|
||||
lights_relax,
|
||||
air_filter,
|
||||
switch,
|
||||
window,
|
||||
}
|
||||
end
|
||||
|
||||
--- @param on boolean
|
||||
function module.set_airfilter_on(on)
|
||||
if air_filter then
|
||||
air_filter:set_on(on)
|
||||
end
|
||||
end
|
||||
|
||||
return module
|
||||
34
config/rooms/guest_bedroom.lua
Normal file
34
config/rooms/guest_bedroom.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
local battery = require("config.battery")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local presence = require("config.presence")
|
||||
local windows = require("config.windows")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local light = devices.LightOnOff.new({
|
||||
name = "Light",
|
||||
room = "Guest Room",
|
||||
topic = helper.mqtt_z2m("guest/light"),
|
||||
client = mqtt_client,
|
||||
})
|
||||
presence.turn_off_when_away(light)
|
||||
|
||||
local window = devices.ContactSensor.new({
|
||||
name = "Window",
|
||||
room = "Guest Room",
|
||||
topic = helper.mqtt_z2m("guest/window"),
|
||||
client = mqtt_client,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
windows.add(window)
|
||||
|
||||
return {
|
||||
light,
|
||||
window,
|
||||
}
|
||||
end
|
||||
|
||||
return module
|
||||
109
config/rooms/hallway_bottom.lua
Normal file
109
config/rooms/hallway_bottom.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
local battery = require("config.battery")
|
||||
local debug = require("config.debug")
|
||||
local devices = require("automation:devices")
|
||||
local hallway_automation = require("config.hallway_automation")
|
||||
local helper = require("config.helper")
|
||||
local hue_bridge = require("config.hue_bridge")
|
||||
local presence = require("config.presence")
|
||||
local utils = require("automation:utils")
|
||||
local windows = require("config.windows")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local main_light = devices.HueGroup.new({
|
||||
identifier = "hallway_main_light",
|
||||
ip = hue_bridge.ip,
|
||||
login = hue_bridge.token,
|
||||
group_id = 81,
|
||||
scene_id = "3qWKxGVadXFFG4o",
|
||||
})
|
||||
hallway_automation.add_callback(function(on)
|
||||
main_light:set_on(on)
|
||||
end)
|
||||
|
||||
local storage_light = devices.LightBrightness.new({
|
||||
name = "Storage",
|
||||
room = "Hallway",
|
||||
topic = helper.mqtt_z2m("hallway/storage"),
|
||||
client = mqtt_client,
|
||||
callback = hallway_automation.light_callback,
|
||||
})
|
||||
presence.turn_off_when_away(storage_light)
|
||||
hallway_automation.add_callback(function(on)
|
||||
if on then
|
||||
storage_light:set_brightness(80)
|
||||
else
|
||||
storage_light:set_on(false)
|
||||
end
|
||||
end)
|
||||
|
||||
local remote = devices.IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Hallway",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("hallway/remote"),
|
||||
callback = hallway_automation.switch_callback,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
local trash = devices.ContactSensor.new({
|
||||
name = "Trash",
|
||||
room = "Hallway",
|
||||
sensor_type = "Drawer",
|
||||
topic = helper.mqtt_z2m("hallway/trash"),
|
||||
client = mqtt_client,
|
||||
callback = hallway_automation.trash_callback,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
hallway_automation.set_trash(trash)
|
||||
|
||||
---@param duration number
|
||||
---@return fun(_, open: boolean)
|
||||
local function frontdoor_presence(duration)
|
||||
local timeout = utils.Timeout.new()
|
||||
|
||||
return function(_, open)
|
||||
if open then
|
||||
timeout:cancel()
|
||||
|
||||
if presence.overall_presence() then
|
||||
mqtt_client:send_message(helper.mqtt_automation("presence/contact/frontdoor"), {
|
||||
state = true,
|
||||
updated = utils.get_epoch(),
|
||||
})
|
||||
end
|
||||
else
|
||||
timeout:start(duration, function()
|
||||
mqtt_client:send_message(helper.mqtt_automation("presence/contact/frontdoor"), nil)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local frontdoor = devices.ContactSensor.new({
|
||||
name = "Frontdoor",
|
||||
room = "Hallway",
|
||||
sensor_type = "Door",
|
||||
topic = helper.mqtt_z2m("hallway/frontdoor"),
|
||||
client = mqtt_client,
|
||||
callback = {
|
||||
frontdoor_presence(debug.debug_mode and 10 or 15 * 60),
|
||||
hallway_automation.door_callback,
|
||||
},
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
windows.add(frontdoor)
|
||||
hallway_automation.set_door(frontdoor)
|
||||
|
||||
return {
|
||||
main_light,
|
||||
storage_light,
|
||||
remote,
|
||||
trash,
|
||||
frontdoor,
|
||||
}
|
||||
end
|
||||
|
||||
return module
|
||||
47
config/rooms/hallway_top.lua
Normal file
47
config/rooms/hallway_top.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
local battery = require("config.battery")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local hue_bridge = require("config.hue_bridge")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local light = devices.HueGroup.new({
|
||||
identifier = "hallway_top_light",
|
||||
ip = hue_bridge.ip,
|
||||
login = hue_bridge.token,
|
||||
group_id = 83,
|
||||
scene_id = "QeufkFDICEHWeKJ7",
|
||||
})
|
||||
|
||||
local top_switch = devices.HueSwitch.new({
|
||||
name = "SwitchTop",
|
||||
room = "Hallway",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("hallway/switchtop"),
|
||||
left_callback = function()
|
||||
light:set_on(not light:on())
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
local bottom_switch = devices.HueSwitch.new({
|
||||
name = "SwitchBottom",
|
||||
room = "Hallway",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("hallway/switchbottom"),
|
||||
left_callback = function()
|
||||
light:set_on(not light:on())
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
return {
|
||||
light,
|
||||
top_switch,
|
||||
bottom_switch,
|
||||
}
|
||||
end
|
||||
|
||||
return module
|
||||
70
config/rooms/kitchen.lua
Normal file
70
config/rooms/kitchen.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
local battery = require("config.battery")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local hue_bridge = require("config.hue_bridge")
|
||||
local presence = require("config.presence")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type HueGroup?
|
||||
local lights = nil
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
lights = devices.HueGroup.new({
|
||||
identifier = "kitchen_lights",
|
||||
ip = hue_bridge.ip,
|
||||
login = hue_bridge.token,
|
||||
group_id = 7,
|
||||
scene_id = "7MJLG27RzeRAEVJ",
|
||||
})
|
||||
|
||||
local kettle = devices.OutletPower.new({
|
||||
outlet_type = "Kettle",
|
||||
name = "Kettle",
|
||||
room = "Kitchen",
|
||||
topic = helper.mqtt_z2m("kitchen/kettle"),
|
||||
client = mqtt_client,
|
||||
callback = helper.auto_off(),
|
||||
})
|
||||
presence.turn_off_when_away(kettle)
|
||||
|
||||
local kettle_remote = devices.IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Kitchen",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("kitchen/remote"),
|
||||
single_button = true,
|
||||
callback = function(_, on)
|
||||
kettle:set_on(on)
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
local kettle_remote_bedroom = devices.IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Bedroom",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("bedroom/remote"),
|
||||
single_button = true,
|
||||
callback = function(_, on)
|
||||
kettle:set_on(on)
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
return {
|
||||
lights,
|
||||
kettle,
|
||||
kettle_remote,
|
||||
kettle_remote_bedroom,
|
||||
}
|
||||
end
|
||||
|
||||
function module.toggle_lights()
|
||||
if lights then
|
||||
lights:set_on(not lights:on())
|
||||
end
|
||||
end
|
||||
|
||||
return module
|
||||
125
config/rooms/living_room.lua
Normal file
125
config/rooms/living_room.lua
Normal file
@@ -0,0 +1,125 @@
|
||||
local battery = require("config.battery")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local hue_bridge = require("config.hue_bridge")
|
||||
local presence = require("config.presence")
|
||||
local windows = require("config.windows")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local lights = devices.HueGroup.new({
|
||||
identifier = "living_lights",
|
||||
ip = hue_bridge.ip,
|
||||
login = hue_bridge.token,
|
||||
group_id = 1,
|
||||
scene_id = "SNZw7jUhQ3cXSjkj",
|
||||
})
|
||||
|
||||
local lights_relax = devices.HueGroup.new({
|
||||
identifier = "living_lights_relax",
|
||||
ip = hue_bridge.ip,
|
||||
login = hue_bridge.token,
|
||||
group_id = 1,
|
||||
scene_id = "eRJ3fvGHCcb6yNw",
|
||||
})
|
||||
|
||||
local switch = devices.HueSwitch.new({
|
||||
name = "Switch",
|
||||
room = "Living",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("living/switch"),
|
||||
left_callback = require("config.rooms.kitchen").toggle_lights,
|
||||
right_callback = function()
|
||||
lights:set_on(not lights:on())
|
||||
end,
|
||||
right_hold_callback = function()
|
||||
lights_relax:set_on(true)
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
local pc = devices.WakeOnLAN.new({
|
||||
name = "Zeus",
|
||||
room = "Living Room",
|
||||
topic = helper.mqtt_automation("appliance/living_room/zeus"),
|
||||
client = mqtt_client,
|
||||
mac_address = "30:9c:23:60:9c:13",
|
||||
broadcast_ip = "10.0.3.255",
|
||||
})
|
||||
|
||||
local mixer = devices.OutletOnOff.new({
|
||||
name = "Mixer",
|
||||
room = "Living Room",
|
||||
topic = helper.mqtt_z2m("living/mixer"),
|
||||
client = mqtt_client,
|
||||
})
|
||||
presence.turn_off_when_away(mixer)
|
||||
|
||||
local speakers = devices.OutletOnOff.new({
|
||||
name = "Speakers",
|
||||
room = "Living Room",
|
||||
topic = helper.mqtt_z2m("living/speakers"),
|
||||
client = mqtt_client,
|
||||
})
|
||||
presence.turn_off_when_away(speakers)
|
||||
|
||||
local audio_remote = devices.IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Living Room",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("living/remote"),
|
||||
single_button = true,
|
||||
callback = function(_, on)
|
||||
if on then
|
||||
if mixer:on() then
|
||||
mixer:set_on(false)
|
||||
speakers:set_on(false)
|
||||
else
|
||||
mixer:set_on(true)
|
||||
speakers:set_on(true)
|
||||
end
|
||||
else
|
||||
if not mixer:on() then
|
||||
mixer:set_on(true)
|
||||
else
|
||||
speakers:set_on(not speakers:on())
|
||||
end
|
||||
end
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
local balcony = devices.ContactSensor.new({
|
||||
name = "Balcony",
|
||||
room = "Living Room",
|
||||
sensor_type = "Door",
|
||||
topic = helper.mqtt_z2m("living/balcony"),
|
||||
client = mqtt_client,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
windows.add(balcony)
|
||||
local window = devices.ContactSensor.new({
|
||||
name = "Window",
|
||||
room = "Living Room",
|
||||
topic = helper.mqtt_z2m("living/window"),
|
||||
client = mqtt_client,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
windows.add(window)
|
||||
|
||||
return {
|
||||
lights,
|
||||
lights_relax,
|
||||
switch,
|
||||
pc,
|
||||
mixer,
|
||||
speakers,
|
||||
audio_remote,
|
||||
balcony,
|
||||
window,
|
||||
}
|
||||
end
|
||||
|
||||
return module
|
||||
40
config/rooms/storage.lua
Normal file
40
config/rooms/storage.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
local battery = require("config.battery")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local presence = require("config.presence")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local light = devices.LightBrightness.new({
|
||||
name = "Light",
|
||||
room = "Storage",
|
||||
topic = helper.mqtt_z2m("storage/light"),
|
||||
client = mqtt_client,
|
||||
})
|
||||
presence.turn_off_when_away(light)
|
||||
|
||||
local door = devices.ContactSensor.new({
|
||||
name = "Door",
|
||||
room = "Storage",
|
||||
sensor_type = "Door",
|
||||
topic = helper.mqtt_z2m("storage/door"),
|
||||
client = mqtt_client,
|
||||
callback = function(_, open)
|
||||
if open then
|
||||
light:set_brightness(100)
|
||||
else
|
||||
light:set_on(false)
|
||||
end
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
return {
|
||||
light,
|
||||
door,
|
||||
}
|
||||
end
|
||||
|
||||
return module
|
||||
68
config/rooms/workbench.lua
Normal file
68
config/rooms/workbench.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
local battery = require("config.battery")
|
||||
local debug = require("config.debug")
|
||||
local devices = require("automation:devices")
|
||||
local helper = require("config.helper")
|
||||
local presence = require("config.presence")
|
||||
local utils = require("automation:utils")
|
||||
|
||||
local module = {}
|
||||
|
||||
--- @type SetupFunction
|
||||
function module.setup(mqtt_client)
|
||||
local charger = devices.OutletOnOff.new({
|
||||
name = "Charger",
|
||||
room = "Workbench",
|
||||
topic = helper.mqtt_z2m("workbench/charger"),
|
||||
client = mqtt_client,
|
||||
callback = helper.off_timeout(debug.debug_mode and 5 or 20 * 3600),
|
||||
})
|
||||
|
||||
local outlets = devices.OutletOnOff.new({
|
||||
name = "Outlets",
|
||||
room = "Workbench",
|
||||
topic = helper.mqtt_z2m("workbench/outlet"),
|
||||
client = mqtt_client,
|
||||
})
|
||||
presence.turn_off_when_away(outlets)
|
||||
|
||||
local light = devices.LightColorTemperature.new({
|
||||
name = "Light",
|
||||
room = "Workbench",
|
||||
topic = helper.mqtt_z2m("workbench/light"),
|
||||
client = mqtt_client,
|
||||
})
|
||||
presence.turn_off_when_away(light)
|
||||
|
||||
local delay_color_temp = utils.Timeout.new()
|
||||
local remote = devices.IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Workbench",
|
||||
client = mqtt_client,
|
||||
topic = helper.mqtt_z2m("workbench/remote"),
|
||||
callback = function(_, on)
|
||||
delay_color_temp:cancel()
|
||||
if on then
|
||||
light:set_brightness(82)
|
||||
-- NOTE: This light does NOT support changing both the brightness and color
|
||||
-- temperature at the same time, so we first change the brightness and once
|
||||
-- that is complete we change the color temperature, as that is less likely
|
||||
-- to have to actually change.
|
||||
delay_color_temp:start(0.5, function()
|
||||
light:set_color_temperature(3333)
|
||||
end)
|
||||
else
|
||||
light:set_on(false)
|
||||
end
|
||||
end,
|
||||
battery_callback = battery.callback,
|
||||
})
|
||||
|
||||
return {
|
||||
charger,
|
||||
outlets,
|
||||
light,
|
||||
remote,
|
||||
}
|
||||
end
|
||||
|
||||
return module
|
||||
Reference in New Issue
Block a user