{ pkgs, lib, config, ... }: { services.mqtt.light-control.enable = true; services.mqtt.light-control.config = { credentials = { host = "tcp://localhost:1883"; user = "homeassistant"; password = "hallo"; }; scenes = [ { name = "default"; } { name = "outside"; room_tracking_enabled = false; } { name = "night"; room_tracking_enabled = false; brightness = 25; exclude_switches = [ "stat/PAL01/RESULT" "stat/PAL03/RESULT" "stat/PAL04/RESULT" "stat/PAL07/RESULT" "stat/PAL08/RESULT" "zigbee2mqtt/light_2" ]; } ]; sensors = let door = { topic, rooms }: { topic = topic; key = "contact"; rooms = rooms; invert_state = true; delay = 90; }; motion = { topic, rooms }: { topic = topic; key = "occupancy"; rooms = rooms; delay = 60; }; in [ (motion { topic = "zigbee2mqtt/motion_sensor_2"; rooms = [ "bed_room" ]; }) (motion { topic = "zigbee2mqtt/motion_sensor_7"; rooms = [ "bed_room" ]; }) (motion { topic = "zigbee2mqtt/motion_sensor_1"; rooms = [ "kitchen_room" ]; }) (motion { topic = "zigbee2mqtt/motion_sensor_3"; rooms = [ "living_room" ]; }) (motion { topic = "zigbee2mqtt/motion_sensor_4"; rooms = [ "living_room" ]; }) (motion { topic = "zigbee2mqtt/motion_sensor_5"; rooms = [ "bath_room" ]; }) (motion { topic = "zigbee2mqtt/motion_sensor_8"; rooms = [ "bath_room" ]; }) (door { topic = "zigbee2mqtt/door_sensor_2"; rooms = [ "floor_room" ]; }) (door { topic = "zigbee2mqtt/door_sensor_4"; rooms = [ "floor_room" ]; }) ]; switches = let sonoff = { id, rooms, delay ? 0 }: { topic = "stat/${id}/RESULT"; key = "POWER"; rooms = rooms; delay = delay; command = { command = "{{state}}"; init_command = "(null)"; topic = "cmnd/${id}/POWER"; on = "ON"; off = "OFF"; }; }; light = { topic, rooms, delay ? 0 }: { topic = topic; key = "state"; rooms = rooms; delay = delay; command = { command = ''{"state":"{{state}}","brightness":{{brightness}}}''; topic = "${topic}/set"; on = "ON"; off = "OFF"; }; }; in [ (light { topic = "zigbee2mqtt/light_1"; rooms = [ "floor_room" ]; }) (light { topic = "zigbee2mqtt/light_2"; rooms = [ "floor_room" ]; }) (light { topic = "zigbee2mqtt/light_3"; rooms = [ "living_room" ]; delay = 10; }) (light { topic = "zigbee2mqtt/light_4"; rooms = [ "bath_room" ]; }) (light { topic = "zigbee2mqtt/light_8"; rooms = [ "bed_room" ]; delay = 10; }) (sonoff { id = "PAL01"; rooms = [ "bed_room" ]; }) (sonoff { id = "PAL03"; rooms = [ "living_room" ]; }) (sonoff { id = "PAL04"; rooms = [ "bed_room" ]; }) (sonoff { id = "PAL06"; rooms = [ "kitchen_room" ]; }) # monitor and speakers (sonoff { id = "PAL07"; rooms = [ "bed_room" ]; delay = 180; }) (sonoff { id = "PAL08"; rooms = [ "bed_room" ]; delay = 180; }) ]; }; }