pepe: home-assistant refactoring
This commit is contained in:
parent
8eed107a3e
commit
55bf10631d
2 changed files with 69 additions and 12 deletions
|
@ -103,7 +103,11 @@ in {
|
|||
view_overview = {
|
||||
name = "Übersicht";
|
||||
view = true;
|
||||
entities = [ "group.today" ];
|
||||
entities = [ "group.today" "group.all_sensors" ];
|
||||
};
|
||||
all_sensors = {
|
||||
name = "Sensor Overview";
|
||||
control = "hidden";
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
let
|
||||
|
||||
# allow new devices to join
|
||||
enablePairing = true;
|
||||
enablePairing = false;
|
||||
|
||||
device = "/dev/ttyACM0";
|
||||
dataFolder = "/srv/zigbee/data";
|
||||
|
@ -27,10 +27,17 @@ let
|
|||
"motion_sensor_7".id = "0x00158d0002f9a6aa";
|
||||
"motion_sensor_8".id = "0x00158d0002f04637";
|
||||
};
|
||||
door = {
|
||||
"door_sensor_1".id = "0x00158d000312dc52";
|
||||
"door_sensor_2".id = "0x00158d000316d5bf";
|
||||
"door_sensor_3".id = "0x00158d0002f9516f";
|
||||
"door_sensor_4".id = "0x00158d00031383b9";
|
||||
"door_sensor_5".id = "0x00158d0003120d3e";
|
||||
};
|
||||
};
|
||||
|
||||
# todo : rename with allSensors
|
||||
allSensors = with sensors; buttons // temperature // motion;
|
||||
# todo : generate automatically
|
||||
allSensors = with sensors; buttons // temperature // motion // door;
|
||||
|
||||
zigBee2MqttConfig = {
|
||||
|
||||
|
@ -76,9 +83,11 @@ in {
|
|||
|
||||
services.homeAssistantConfig = {
|
||||
|
||||
# group.unknown.entities = [ "sensor.button_1" ];
|
||||
|
||||
# define sensors
|
||||
# --------------
|
||||
sensor = let
|
||||
|
||||
# define button sensors
|
||||
buttons = with lib;
|
||||
mapAttrsToList (name:
|
||||
{ ... }: [{
|
||||
|
@ -90,6 +99,7 @@ in {
|
|||
value_template = "{{ value_json.click }}";
|
||||
}]) sensors.buttons;
|
||||
|
||||
# define temperature sensors
|
||||
temperature = with lib;
|
||||
mapAttrsToList (name:
|
||||
{ ... }: [
|
||||
|
@ -122,6 +132,7 @@ in {
|
|||
}
|
||||
]) sensors.temperature;
|
||||
|
||||
# define meta information sensors
|
||||
informations = lib.mapAttrsToList (name:
|
||||
{ ... }: [
|
||||
{
|
||||
|
@ -146,8 +157,12 @@ in {
|
|||
|
||||
in lib.flatten (buttons ++ temperature ++ informations);
|
||||
|
||||
# define binary sensors
|
||||
# ---------------------
|
||||
binary_sensor = let
|
||||
|
||||
# define motion sensors
|
||||
# ---------------------
|
||||
motion = lib.mapAttrsToList (name:
|
||||
{ ... }: {
|
||||
name = name;
|
||||
|
@ -159,13 +174,31 @@ in {
|
|||
payload_off = false;
|
||||
value_template = "{{ value_json.occupancy }}";
|
||||
}) sensors.motion;
|
||||
in lib.flatten (motion);
|
||||
|
||||
# define door sensors
|
||||
# -------------------
|
||||
door = lib.mapAttrsToList (name:
|
||||
{ ... }: {
|
||||
name = name;
|
||||
platform = "mqtt";
|
||||
device_class = "door";
|
||||
state_topic = "zigbee2mqtt/${name}";
|
||||
availability_topic = "zigbee2mqtt/bridge/state";
|
||||
payload_on = false;
|
||||
payload_off = true;
|
||||
value_template = "{{ value_json.contact}}";
|
||||
}) sensors.door;
|
||||
|
||||
in lib.flatten (motion ++ door);
|
||||
|
||||
# create groups
|
||||
# -------------
|
||||
# to have nice panels for every device
|
||||
group = let
|
||||
|
||||
information = name: [ "sensor.battery_${name}" "sensor.link_${name}" ];
|
||||
|
||||
sensor = lib.mapAttrs' (name:
|
||||
sensorButtons = lib.mapAttrs' (name:
|
||||
{ ... }: {
|
||||
name = name;
|
||||
value = {
|
||||
|
@ -187,7 +220,7 @@ in {
|
|||
};
|
||||
}) (sensors.temperature);
|
||||
|
||||
binarySensor = lib.mapAttrs' (name:
|
||||
sensorMotions = lib.mapAttrs' (name:
|
||||
{ ... }: {
|
||||
name = name;
|
||||
value = {
|
||||
|
@ -196,6 +229,15 @@ in {
|
|||
};
|
||||
}) (sensors.motion);
|
||||
|
||||
sensorDoors = lib.mapAttrs' (name:
|
||||
{ ... }: {
|
||||
name = name;
|
||||
value = {
|
||||
control = "hidden";
|
||||
entities = [ "binary_sensor.${name}" ] ++ (information name);
|
||||
};
|
||||
}) (sensors.door);
|
||||
|
||||
views = {
|
||||
view_sensors = {
|
||||
name = "Sensoren";
|
||||
|
@ -206,8 +248,18 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
in views // sensor // binarySensor // sensorTemperature;
|
||||
in views // sensorButtons // sensorMotions // sensorTemperature
|
||||
// sensorDoors // {
|
||||
all_sensors.entities =
|
||||
(lib.mapAttrsToList (name: { ... }: "sensor.${name}")
|
||||
(sensors.buttons // sensors.temperature))
|
||||
++ (lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}")
|
||||
(sensors.motion // sensors.door));
|
||||
};
|
||||
|
||||
# create automation
|
||||
# -----------------
|
||||
# todo : this belongs in the home-assistant.nix
|
||||
automation = let
|
||||
|
||||
lights = map (button: {
|
||||
|
@ -281,10 +333,11 @@ in {
|
|||
|
||||
};
|
||||
|
||||
virtualisation.docker.enable = true;
|
||||
# manage zigbee2mqtt
|
||||
# ------------------
|
||||
|
||||
# todo : einen eigenen container bauen mit dockerTool : https://nixos.wiki/wiki/Docker
|
||||
|
||||
virtualisation.docker.enable = true;
|
||||
systemd.services."zigbee2mqtt" = {
|
||||
enable = true;
|
||||
description =
|
||||
|
|
Loading…
Reference in a new issue