WIP: Made config modular
This commit is contained in:
9
config/helper.lua
Normal file
9
config/helper.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
return {
|
||||
mqtt_z2m = function(topic)
|
||||
return "zigbee2mqtt/" .. topic
|
||||
end,
|
||||
|
||||
mqtt_automation = function(topic)
|
||||
return "automation/" .. topic
|
||||
end,
|
||||
}
|
||||
35
config/kettle.lua
Normal file
35
config/kettle.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
local h = require("helper")
|
||||
|
||||
return function(mqtt_client, debug)
|
||||
local kettle = IkeaOutlet.new({
|
||||
outlet_type = "Kettle",
|
||||
name = "Kettle",
|
||||
room = "Kitchen",
|
||||
topic = h.mqtt_z2m("kitchen/kettle"),
|
||||
client = mqtt_client,
|
||||
timeout = debug and 5 or 300,
|
||||
})
|
||||
automation.device_manager:add(kettle)
|
||||
|
||||
local function set_kettle(on)
|
||||
kettle:set_on(on)
|
||||
end
|
||||
|
||||
automation.device_manager:add(IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Bedroom",
|
||||
client = mqtt_client,
|
||||
topic = h.mqtt_z2m("bedroom/remote"),
|
||||
single_button = true,
|
||||
callback = set_kettle,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Kitchen",
|
||||
client = mqtt_client,
|
||||
topic = h.mqtt_z2m("kitchen/remote"),
|
||||
single_button = true,
|
||||
callback = set_kettle,
|
||||
}))
|
||||
end
|
||||
198
config/main.lua
Normal file
198
config/main.lua
Normal file
@@ -0,0 +1,198 @@
|
||||
print(package.path)
|
||||
print("Hello from lua")
|
||||
|
||||
local host = automation.util.get_hostname()
|
||||
print("Running @" .. host)
|
||||
|
||||
local debug, value = pcall(automation.util.get_env, "DEBUG")
|
||||
if debug and value ~= "true" then
|
||||
debug = false
|
||||
end
|
||||
|
||||
local h = require("helper")
|
||||
|
||||
automation.fulfillment = {
|
||||
openid_url = "https://login.huizinga.dev/api/oidc",
|
||||
}
|
||||
|
||||
local mqtt_client = automation.new_mqtt_client({
|
||||
host = (host == "zeus" and "olympus.lan.huizinga.dev")
|
||||
or (host == "hephaestus" and "olympus.vpn.huizinga.dev")
|
||||
or "mosquitto",
|
||||
port = 8883,
|
||||
client_name = "automation-" .. host,
|
||||
username = "mqtt",
|
||||
password = automation.util.get_env("MQTT_PASSWORD"),
|
||||
tls = host == "zeus" or host == "hephaestus",
|
||||
})
|
||||
|
||||
automation.device_manager:add(Ntfy.new({
|
||||
topic = automation.util.get_env("NTFY_TOPIC"),
|
||||
event_channel = automation.device_manager:event_channel(),
|
||||
}))
|
||||
|
||||
automation.device_manager:add(Presence.new({
|
||||
topic = h.mqtt_automation("presence/+/#"),
|
||||
client = mqtt_client,
|
||||
event_channel = automation.device_manager:event_channel(),
|
||||
}))
|
||||
|
||||
automation.device_manager:add(DebugBridge.new({
|
||||
identifier = "debug_bridge",
|
||||
topic = h.mqtt_automation("debug"),
|
||||
client = mqtt_client,
|
||||
}))
|
||||
|
||||
local hue_ip = "10.0.0.136"
|
||||
local hue_token = automation.util.get_env("HUE_TOKEN")
|
||||
|
||||
automation.device_manager:add(HueBridge.new({
|
||||
identifier = "hue_bridge",
|
||||
ip = hue_ip,
|
||||
login = hue_token,
|
||||
flags = {
|
||||
presence = 41,
|
||||
darkness = 43,
|
||||
},
|
||||
}))
|
||||
|
||||
automation.device_manager:add(LightSensor.new({
|
||||
identifier = "living_light_sensor",
|
||||
topic = h.mqtt_z2m("living/light"),
|
||||
client = mqtt_client,
|
||||
min = 22000,
|
||||
max = 23500,
|
||||
event_channel = automation.device_manager:event_channel(),
|
||||
}))
|
||||
|
||||
automation.device_manager:add(WakeOnLAN.new({
|
||||
name = "Zeus",
|
||||
room = "Living Room",
|
||||
topic = h.mqtt_automation("appliance/living_room/zeus"),
|
||||
client = mqtt_client,
|
||||
mac_address = "30:9c:23:60:9c:13",
|
||||
broadcast_ip = "10.0.0.255",
|
||||
}))
|
||||
|
||||
local living_mixer = KasaOutlet.new({ identifier = "living_mixer", ip = "10.0.0.84" })
|
||||
automation.device_manager:add(living_mixer)
|
||||
local living_speakers = KasaOutlet.new({ identifier = "living_speakers", ip = "10.0.0.127" })
|
||||
automation.device_manager:add(living_speakers)
|
||||
|
||||
automation.device_manager:add(IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Living",
|
||||
client = mqtt_client,
|
||||
topic = h.mqtt_z2m("living/remote"),
|
||||
single_button = true,
|
||||
callback = function(on)
|
||||
if on then
|
||||
if living_mixer:is_on() then
|
||||
living_mixer:set_on(false)
|
||||
living_speakers:set_on(false)
|
||||
else
|
||||
living_mixer:set_on(true)
|
||||
living_speakers:set_on(true)
|
||||
end
|
||||
else
|
||||
if not living_mixer:is_on() then
|
||||
living_mixer:set_on(true)
|
||||
else
|
||||
living_speakers:set_on(not living_speakers:is_on())
|
||||
end
|
||||
end
|
||||
end,
|
||||
}))
|
||||
|
||||
require("kettle")(mqtt_client, debug)
|
||||
|
||||
automation.device_manager:add(IkeaOutlet.new({
|
||||
outlet_type = "Light",
|
||||
name = "Light",
|
||||
room = "Bathroom",
|
||||
topic = h.mqtt_z2m("bathroom/light"),
|
||||
client = mqtt_client,
|
||||
timeout = debug and 60 or 45 * 60,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(Washer.new({
|
||||
identifier = "bathroom_washer",
|
||||
topic = h.mqtt_z2m("bathroom/washer"),
|
||||
client = mqtt_client,
|
||||
threshold = 1,
|
||||
event_channel = automation.device_manager:event_channel(),
|
||||
}))
|
||||
|
||||
automation.device_manager:add(IkeaOutlet.new({
|
||||
outlet_type = "Charger",
|
||||
name = "Charger",
|
||||
room = "Workbench",
|
||||
topic = h.mqtt_z2m("workbench/charger"),
|
||||
client = mqtt_client,
|
||||
timeout = debug and 5 or 20 * 3600,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(IkeaOutlet.new({
|
||||
name = "Outlet",
|
||||
room = "Workbench",
|
||||
topic = h.mqtt_z2m("workbench/outlet"),
|
||||
client = mqtt_client,
|
||||
}))
|
||||
|
||||
local hallway_lights = HueGroup.new({
|
||||
identifier = "hallway_lights",
|
||||
ip = hue_ip,
|
||||
login = hue_token,
|
||||
group_id = 81,
|
||||
scene_id = "3qWKxGVadXFFG4o",
|
||||
timer_id = 1,
|
||||
client = mqtt_client,
|
||||
})
|
||||
automation.device_manager:add(hallway_lights)
|
||||
automation.device_manager:add(IkeaRemote.new({
|
||||
name = "Remote",
|
||||
room = "Hallway",
|
||||
client = mqtt_client,
|
||||
topic = h.mqtt_z2m("hallway/remote"),
|
||||
callback = function(on)
|
||||
hallway_lights:set_on(on)
|
||||
end,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(ContactSensor.new({
|
||||
identifier = "hallway_frontdoor",
|
||||
topic = h.mqtt_z2m("hallway/frontdoor"),
|
||||
client = mqtt_client,
|
||||
presence = {
|
||||
topic = h.mqtt_automation("presence/contact/frontdoor"),
|
||||
timeout = debug and 10 or 15 * 60,
|
||||
},
|
||||
trigger = {
|
||||
devices = { hallway_lights },
|
||||
timeout = debug and 10 or 2 * 60,
|
||||
},
|
||||
}))
|
||||
|
||||
automation.device_manager:add(ContactSensor.new({
|
||||
identifier = "hallway_trash",
|
||||
topic = h.mqtt_z2m("hallway/trash"),
|
||||
client = mqtt_client,
|
||||
trigger = {
|
||||
devices = { hallway_lights },
|
||||
},
|
||||
}))
|
||||
|
||||
local bedroom_air_filter = AirFilter.new({
|
||||
name = "Air Filter",
|
||||
room = "Bedroom",
|
||||
topic = "pico/filter/bedroom",
|
||||
client = mqtt_client,
|
||||
})
|
||||
automation.device_manager:add(bedroom_air_filter)
|
||||
|
||||
automation.device_manager:schedule("0 0 19 * * *", function()
|
||||
bedroom_air_filter:set_on(true)
|
||||
end)
|
||||
automation.device_manager:schedule("0 0 20 * * *", function()
|
||||
bedroom_air_filter:set_on(false)
|
||||
end)
|
||||
Reference in New Issue
Block a user