nixos-config/configs/pepe/home-assistant/light-control.nix
2020-12-06 23:54:46 +01:00

179 lines
4.2 KiB
Nix

{ pkgs, lib, config, ... }: {
services.mqtt.light-control.enable = true;
services.mqtt.light-control.loglevel = "debug";
services.mqtt.light-control.config = {
credentials = {
host = "tcp://localhost:1883";
user = "homeassistant";
password = "hallo";
};
scenes = [
{ name = "default"; }
{
name = "outside";
room_tracking_enabled = false;
ignored_sensors = [ "zigbee2mqtt/door_sensor_4" ];
}
{
name = "night";
room_tracking_enabled = false;
brightness = 25;
#disabled_switches = [
#"zigbee2mqtt/light_2"
#];
ignored_sensors = [ "zigbee2mqtt/motion_sensor_7" ];
}
];
sensors = let
door = { topic, room }: {
topic = topic;
key = "contact";
room = room;
invert_state = true;
delay = 90;
};
motion = { topic, room }: {
topic = topic;
key = "occupancy";
room = room;
delay = 60;
};
in [
(motion {
topic = "zigbee2mqtt/motion_sensor_1";
room = "office_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_2";
room = "office_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_6";
room = "office_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_7";
room = "sleeping_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_5";
room = "kitchen";
})
(door {
topic = "zigbee2mqtt/door_sensor_1";
room = "storage_room";
})
(door {
topic = "zigbee2mqtt/door_sensor_5";
room = "sleeping_room";
})
(door {
# house door
topic = "zigbee2mqtt/door_sensor_4";
room = "floor";
})
];
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";
};
};
led = { topic, rooms, delay ? 0 }: {
topic = topic;
key = "state";
rooms = rooms;
delay = delay;
command = {
# Configure it once to the color you like
# {"state":"{{state}}","brightness":{{brightness}},"color":{"hex":"#FFFFFF},"color_temp":255","transition":0}
command = ''
{"state":"{{state}}","brightness":{{brightness}},"transition":0}'';
topic = "${topic}/set";
on = "ON";
off = "OFF";
};
};
in [
(light {
topic = "zigbee2mqtt/light_2";
rooms = [ "office_room" ];
})
(light {
topic = "zigbee2mqtt/light_4";
rooms = [ "office_room" ];
})
(light {
topic = "zigbee2mqtt/light_5";
rooms = [ "storage_room" ];
})
(light {
topic = "zigbee2mqtt/light_7";
rooms = [ "sleeping_room" ];
})
(led {
topic = "zigbee2mqtt/led_1";
rooms = [ "office_room" ];
})
(led {
topic = "zigbee2mqtt/led_2";
rooms = [ "kitchen" ];
})
#(sonoff {
# id = "PAL01";
# rooms = [ "bed_room" ];
#})
#(sonoff {
# id = "PAL03";
# rooms = [ "living_room" ];
#})
#(sonoff {
# id = "PAL04";
# rooms = [ "bed_room" ];
#})
#(sonoff {
# id = "PAL06";
# rooms = [ "kitchen" ];
#})
## monitor and speakers
#(sonoff {
# id = "PAL07";
# rooms = [ "bed_room" ];
# delay = 180;
#})
#(sonoff {
# id = "PAL08";
# rooms = [ "bed_room" ];
# delay = 180;
#})
];
};
}