home-assistant: thin out stuff which is not needed anymore

This commit is contained in:
Ingolf Wagner 2020-06-01 23:20:15 +02:00
parent 511b0ca79d
commit a0a707993b
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
15 changed files with 268 additions and 673 deletions

View file

@ -19,67 +19,95 @@ in {
services.homeAssistantConfig = { services.homeAssistantConfig = {
# turn on to edit GUI # turn on to edit GUI
# lovelace = {}; lovelace = { };
homeassistant = { homeassistant = {
name = "Home";
latitude = 51.444847; latitude = 51.444847;
longitude = 6.967006; longitude = 6.967006;
elevation = 116; elevation = 116;
unit_system = "metric";
time_zone = config.time.timeZone;
auth_providers = [{ auth_providers = [{
type = "trusted_networks"; type = "trusted_networks";
trusted_networks = trusted_networks =
[ config.module.cluster.services.tinc."private".networkSubnet ]; [ config.module.cluster.services.tinc."private".networkSubnet ];
}]; }];
}; };
# needed, don't know why
default_config = { };
config = { };
# to grab metrics via prometheus
prometheus.namespace = "hass"; prometheus.namespace = "hass";
# manual state # manual state
# ------------ # ------------
input_select.situation = { # all scenes
input_select.scene = {
icon = "mdi:brightness-auto"; icon = "mdi:brightness-auto";
options = [ "default" "night" "outside" ]; options = [ "default" "night" "outside" ];
}; };
# scenes controlled by buttons
input_select.scene_button = {
icon = "mdi:brightness-auto";
options = [ "default" "night" ];
};
input_boolean.situation_toggle.icon = "mdi:toggle-switch"; input_boolean.situation_toggle.icon = "mdi:toggle-switch";
automation = [ automation = [
{
# This automation script runs when the thermostat mode selector is changed.
# It publishes its value to the same MQTT topic it is also subscribed to.
alias = "Mqtt publish Scene";
trigger = {
platform = "state";
entity_id = "input_select.scene";
};
action = {
service = "mqtt.publish";
data_template = {
topic = "control/lights/set";
#retain = true;
payload_template =
''{"scene":"{{ states('input_select.scene')}}"}'';
};
};
}
# control situation with buttons # control situation with buttons
{ {
alias = "set night scene"; alias = "Toggle Button (controlled) Scene";
trigger = { trigger = {
platform = "state"; platform = "state";
entity_id = "input_boolean.situation_toggle"; entity_id = "input_boolean.situation_toggle";
from = "off";
to = "on";
}; };
action = { action = {
service = "mqtt.publish"; service = "input_select.select_next";
data = { data.entity_id = "input_select.scene_button";
topic = "control/lights/set"; };
payload = builtins.toJSON { scene = "night"; }; }
{
alias = "Button Scene -> Scene";
trigger = {
platform = "state";
entity_id = "input_select.scene_button";
};
action = {
service = "input_select.select_option";
data_template = {
entity_id = "input_select.scene";
option = "{{ states('input_select.scene_button') }}";
}; };
}; };
} }
{ {
alias = "set default scene"; alias = "Set Scene To Outside when opening door";
trigger = {
platform = "state";
entity_id = "input_boolean.situation_toggle";
from = "on";
to = "off";
};
action = {
service = "mqtt.publish";
data = {
topic = "control/lights/set";
payload = builtins.toJSON { scene = "default"; };
};
};
}
{
alias = "set outside scene";
trigger = [ trigger = [
{ {
platform = "state"; platform = "state";
@ -97,10 +125,10 @@ in {
} }
]; ];
action = { action = {
service = "mqtt.publish"; service = "input_select.select_option";
data = { data = {
topic = "control/lights/set"; entity_id = "input_select.scene";
payload = builtins.toJSON { scene = "outside"; }; option = "outside";
}; };
}; };
} }
@ -111,44 +139,8 @@ in {
create_room = { name, description }: { create_room = { name, description }: {
"${name}" = { "${name}" = {
name = "${description}"; name = "${description}";
view = false;
control = "hidden";
entities = [ ]; entities = [ ];
}; };
"${name}_lights" = {
name = "${description} Beleuchtung";
view = false;
entities = [ ];
};
"${name}_present" = {
control = "hidden";
name = "${description} Anwesend";
view = false;
entities = [ ];
};
"${name}_essential" = {
control = "hidden";
name = "${description} Minimale Beleuchtung";
view = false;
entities = [ ];
};
"${name}_bright" = {
control = "hidden";
name = "${description} Tages Beleuchtung";
view = false;
entities = [ ];
};
"view_${name}" = {
name = description;
view = true;
entities = [
"group.${name}"
"group.${name}_bright"
"group.${name}_essential"
"group.${name}_lights"
"group.${name}_present"
];
};
}; };
create_rooms = rooms: create_rooms = rooms:
lib.foldr (a: b: a // b) { } (map create_room rooms); lib.foldr (a: b: a // b) { } (map create_room rooms);
@ -176,118 +168,60 @@ in {
description = "Klo"; description = "Klo";
} }
]) // { ]) // {
view_rooms = {
name = "Räume";
view = true;
entities = [
"group.today"
"group.floor_room"
"group.bed_room"
"group.living_room"
"group.kitchen_room"
"group.bath_room"
];
};
all_room_presents = {
name = "Alle Anwesenheits Raum Sensoren";
entities = [
"group.floor_room_present"
"group.bed_room_present"
"group.living_room_present"
"group.kitchen_room_present"
"group.bath_room_present"
];
};
outside = {
name = "Draußen";
entities = [ ];
};
# overview # overview
# -------- # --------
all_sensors = { all_sensors = { name = "Alle Sensoren"; };
name = "Alle Sensoren";
control = "hidden";
};
today = { today = {
control = "hidden";
name = "Today"; name = "Today";
view = false; entities = [ "input_select.scene" ];
entities = [
"input_select.situation"
"input_select.room_present"
"input_boolean.presents_tracking"
];
}; };
view_overview = {
name = "Übersicht";
view = true;
entities = [ "group.today" ];
};
# other stuff # other stuff
# ----------- # -----------
tv = { tv = { name = "TV"; };
name = "TV"; all_lights = { name = "Alle Lampen"; };
view = false;
};
all_lights = {
name = "Alle Lampen";
view = false;
};
unknown = { unknown = {
control = "hidden";
name = "Not Used"; name = "Not Used";
view = false;
entities = [ ]; entities = [ ];
}; };
}; };
script.turn_all_off.sequence = [ ];
script.turn_all_lights_off.sequence = [ ];
}; };
services.home-assistant = { services.home-assistant = {
enable = true; enable = true;
package = unstablePkgs.home-assistant.override { #package = unstablePkgs.home-assistant.override {
python3 = unstablePkgs.python37; # python3 = unstablePkgs.python37;
extraPackages = python: [ # extraPackages = python: [
# todo : check which is still needed # # todo : check which is still needed
python.netdisco # python.netdisco
python.xmltodict # python.xmltodict
python.mpd2 # python.mpd2
# # for mqtt
# for mqtt # python.hbmqtt
python.hbmqtt # python.paho-mqtt
python.paho-mqtt # # needed for platform workday
# #(python.buildPythonPackage rec {
# needed for platform workday # # pname = "holidays";
#(python.buildPythonPackage rec { # # version = "0.9.10";
# pname = "holidays"; # # src = python.fetchPypi {
# version = "0.9.10"; # # inherit pname version;
# src = python.fetchPypi { # # sha256 =
# inherit pname version; # # "9f06d143eb708e8732230260636938f2f57114e94defd8fa2082408e0d422d6f";
# sha256 = # # };
# "9f06d143eb708e8732230260636938f2f57114e94defd8fa2082408e0d422d6f"; # # doCheck = false;
# # buildInputs = [ pkgs.dateutils ];
# # propagatedBuildInputs = [ python."python-dateutil" python."six" ];
# # meta = with pkgs.stdenv.lib; {
# # homepage = "https://github.com/dr-prodigy/python-holidays";
# # license = licenses.mit;
# # description = "Generate and work with holidays in Python";
# # maintainers = with maintainers; [ mrVanDalo ];
# # };
# #})
# ];
#}; #};
# doCheck = false;
# buildInputs = [ pkgs.dateutils ];
# propagatedBuildInputs = [ python."python-dateutil" python."six" ];
# meta = with pkgs.stdenv.lib; {
# homepage = "https://github.com/dr-prodigy/python-holidays";
# license = licenses.mit;
# description = "Generate and work with holidays in Python";
# maintainers = with maintainers; [ mrVanDalo ];
# };
#})
];
};
}; };

View file

@ -42,10 +42,8 @@ in {
group = { group = {
"${name}" = { "${name}" = {
name = "ChaosPott (Essen)"; name = "ChaosPott (Essen)";
control = "hidden";
entities = [ "sensor.${name}_aerie" "sensor.${name}_cellar" ]; entities = [ "sensor.${name}_aerie" "sensor.${name}_cellar" ];
}; };
view_overview.entities = [ "group.${name}" ];
}; };
}; };

View file

@ -2,8 +2,6 @@
services.homeAssistantConfig = { services.homeAssistantConfig = {
group.view_overview.entities = [ "media_player.kodi" ];
media_player = [{ media_player = [{
platform = "kodi"; platform = "kodi";
host = "127.0.0.1"; host = "127.0.0.1";

View file

@ -1,11 +1,4 @@
{ pkgs, lib, config, ... }: { { pkgs, lib, config, ... }: {
#systemd.services."light-control" = {
# wantedBy = [ "multi-user.target" ];
# environment = { RUST_LOG = "rust_iot=trace"; };
# script = ''
# ${pkgs.light-control}/bin/rust-iot ${lightControlConfig}
# '';
#};
services.mqtt.light-control.enable = true; services.mqtt.light-control.enable = true;
services.mqtt.light-control.config = { services.mqtt.light-control.config = {
@ -112,7 +105,6 @@
}; };
}; };
in [ in [
(light { (light {
topic = "zigbee2mqtt/light_1"; topic = "zigbee2mqtt/light_1";
rooms = [ "floor_room" ]; rooms = [ "floor_room" ];

View file

@ -3,35 +3,11 @@
{ {
services.homeAssistantConfig = { services.homeAssistantConfig = {
group.view_overview.entities = [ "media_player.mpd" ];
media_player = [{ media_player = [{
platform = "mpd"; platform = "mpd";
host = "localhost"; host = "localhost";
}]; }];
script.turn_all_off.sequence = [{
alias = "turn mpd off";
service = "media_player.turn_off";
data.entity_id = "media_player.mpd";
}];
script.turn_all_on.sequence = [
{
alias = "turn mpd on";
service = "media_player.turn_on";
data.entity_id = "media_player.mpd";
}
{
alias = "Adjust volume";
service = "media_player.volume_set";
data = {
entity_id = "media_player.mpd";
volume_level = "0.90";
};
}
];
}; };
} }

View file

@ -2,43 +2,37 @@
let let
sonoffSwitches = { sonoffSwitches = {
"pal01" = { #"pal01" = {
label = "Schlafzimmer Lampe Links"; # label = "Schlafzimmer Lampe Links";
icon = "mdi:lightbulb"; # icon = "mdi:lightbulb";
groups = [ "all_lights" "bed_room_lights" "bed_room_bright" "bed_room" ]; # groups = [ "bed_room" ];
}; #};
"pal02" = { "pal02" = {
label = "Drucker / Scanner"; label = "Drucker / Scanner";
icon = "mdi:printer"; icon = "mdi:printer";
groups = [ "bed_room" "today" ]; groups = [ "bed_room" "today" ];
}; };
"pal03" = { #"pal03" = {
label = "Wohnzimmer Lampe"; # label = "Wohnzimmer Lampe";
icon = "mdi:lightbulb"; # icon = "mdi:lightbulb";
groups = [ "all_lights" "living_room_lights" "living_room" ]; # groups = [ "living_room" ];
}; #};
"pal04" = { #"pal04" = {
label = "Schlafzimmer Lampe Rechts"; # label = "Schlafzimmer Lampe Rechts";
icon = "mdi:lightbulb"; # icon = "mdi:lightbulb";
groups = [ "all_lights" "bed_room_lights" "bed_room_bright" "bed_room" ]; # groups = [ "bed_room" ];
}; #};
"pal05" = { "pal05" = {
label = "TV"; label = "TV";
icon = "mdi:television"; icon = "mdi:television";
groups = [ "tv" "living_room" "today" ]; groups = [ "tv" ];
device = "tv"; device = "tv";
}; };
"pal06" = { #"pal06" = {
label = "Küchen Lampe"; # label = "Küchen Lampe";
icon = "mdi:lightbulb"; # icon = "mdi:lightbulb";
groups = [ # groups = ["kitchen_room"];
"all_lights" #};
"kitchen_room"
"kitchen_room_bright"
"kitchen_room_essential"
"kitchen_room_lights"
];
};
"pal07" = { label = "Nummer 7"; }; "pal07" = { label = "Nummer 7"; };
"pal08" = { label = "Nummer 8"; }; "pal08" = { label = "Nummer 8"; };
}; };

View file

@ -97,18 +97,11 @@ in {
]) stocks)); ]) stocks));
}; };
group = { group = (builtins.listToAttrs (map
"stocks" = { ({ name, friendly_name, own ? { }, ... }: {
name = "Aktien";
view = true;
control = "hidden";
entities = map ({ name, ... }: "group.stock_${name}") stocks;
};
} // (builtins.listToAttrs (map ({ name, friendly_name, own ? { }, ... }: {
name = "stock_${name}"; name = "stock_${name}";
value = { value = {
name = friendly_name; name = "${friendly_name} Aktie";
control = "hidden";
entities = [ entities = [
"sensor.stock_${name}" "sensor.stock_${name}"
"sensor.stock_${name}_change" "sensor.stock_${name}_change"

View file

@ -81,9 +81,7 @@
group = { group = {
timer_wakeup = { timer_wakeup = {
view = false;
name = "Arbeits Aufwachen"; name = "Arbeits Aufwachen";
control = "hidden";
entities = [ entities = [
"input_boolean.wakeup" "input_boolean.wakeup"
"input_datetime.wakeup" "input_datetime.wakeup"
@ -92,23 +90,12 @@
}; };
timer_leave = { timer_leave = {
view = false;
name = "Leave Time"; name = "Leave Time";
control = "hidden";
entities = [ "input_boolean.leave" "input_datetime.leave" ]; entities = [ "input_boolean.leave" "input_datetime.leave" ];
}; };
timer_return = { timer_return = {
view = false;
name = "Nach Hause kommen"; name = "Nach Hause kommen";
control = "hidden";
entities = [ "input_boolean.return" "input_datetime.return" ];
};
timer_sleep = {
view = false;
name = "Einschlafen";
control = "hidden";
entities = [ "input_boolean.sleep" "input_datetime.sleep" ]; entities = [ "input_boolean.sleep" "input_datetime.sleep" ];
}; };
@ -123,12 +110,6 @@
today.entities = [ "sensor.date" "sensor.time" ]; today.entities = [ "sensor.date" "sensor.time" ];
view_overview.entities = [
"group.timer_wakeup"
"group.timer_leave"
"group.timer_return"
"group.timer_sleep"
];
}; };
automation = [ automation = [

View file

@ -34,7 +34,6 @@
group = { group = {
today.entities = today.entities =
[ "binary_sensor.before_workday" "binary_sensor.workday" ]; [ "binary_sensor.before_workday" "binary_sensor.workday" ];
view_overview.entities = [ "group.is_workday" ];
}; };
}; };

View file

@ -118,7 +118,6 @@ in {
hold hold
]; ];
in { in {
control = "hidden";
entities = [ "sensor.${name}" ] ++ (entityIds states) entities = [ "sensor.${name}" ] ++ (entityIds states)
++ [ "sensor.battery_${name}" "sensor.link_${name}" ]; ++ [ "sensor.battery_${name}" "sensor.link_${name}" ];
}) allDevices; }) allDevices;

View file

@ -9,7 +9,7 @@ let
}; };
"door_sensor_2" = { "door_sensor_2" = {
id = "0x00158d000316d5bf"; id = "0x00158d000316d5bf";
groups = [ "floor_room" "floor_room_present" "outside" ]; groups = [ "floor_room" ];
}; };
"window_sensor_3" = { "window_sensor_3" = {
id = "0x00158d0002f9516f"; id = "0x00158d0002f9516f";
@ -17,7 +17,7 @@ let
}; };
"door_sensor_4" = { "door_sensor_4" = {
id = "0x00158d00031383b9"; id = "0x00158d00031383b9";
groups = [ "floor_room" "floor_room_present" ]; groups = [ "floor_room" ];
}; };
"window_sensor_5" = { "window_sensor_5" = {
id = "0x00158d0003120d3e"; id = "0x00158d0003120d3e";
@ -76,19 +76,15 @@ in {
# create groups # create groups
# ------------- # -------------
group = let group = let
# to have nice panels for every device # to have nice panels for every device
sensorGroups = lib.mapAttrs (name: sensorGroups = lib.mapAttrs (name:
{ ... }: { { ... }: {
control = "hidden";
entities = [ entities = [
"binary_sensor.${name}" "binary_sensor.${name}"
"sensor.battery_${name}" "sensor.battery_${name}"
"sensor.link_${name}" "sensor.link_${name}"
]; ];
}) allDevices; }) allDevices;
# sort lights into given groups. # sort lights into given groups.
sortedInGroups = let sortedInGroups = let
groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name: groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
@ -96,12 +92,11 @@ in {
map (groupName: { "${groupName}" = "binary_sensor.${name}"; }) groups) map (groupName: { "${groupName}" = "binary_sensor.${name}"; }) groups)
allDevices)); allDevices));
in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries; in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
in sortedInGroups // sensorGroups // { in sortedInGroups // sensorGroups // {
all_sensors.entities = all_sensors.entities =
lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}") allDevices; lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}") allDevices;
}; };
}; };
} }

View file

@ -14,28 +14,22 @@ let
}; };
"light_2" = { "light_2" = {
id = "0x7cb03eaa0a0387b9"; id = "0x7cb03eaa0a0387b9";
groups = [ "floor_room" "floor_room_lights" ]; groups = [ "floor_room" ];
}; };
"light_3" = { "light_3" = {
id = "0x7cb03eaa0a033a86"; id = "0x7cb03eaa0a033a86";
groups = [ "living_room" "living_room_essential" "living_room_lights" ]; groups = [ "living_room" ];
}; };
"light_4" = { "light_4" = {
id = "0x7cb03eaa0a04aabf"; id = "0x7cb03eaa0a04aabf";
groups = [ groups = [ "bath_room" ];
"bath_room"
"bath_room_bright"
"bath_room_essential"
"bath_room_lights"
];
}; };
"light_5" = { id = "0x7cb03eaa0a0346e4"; }; "light_5" = { id = "0x7cb03eaa0a0346e4"; };
"light_6" = { id = "0x7cb03eaa0a034b46"; }; "light_6" = { id = "0x7cb03eaa0a034b46"; };
"light_7" = { id = "0x7cb03eaa0a033b4f"; }; "light_7" = { id = "0x7cb03eaa0a033b4f"; };
"light_8" = { "light_8" = {
id = "0x7cb03eaa0a0384d3"; id = "0x7cb03eaa0a0384d3";
groups = groups = [ "bed_room" ];
[ "bed_room" "bed_room_essential" "bed_room_lights" "bed_room_bright" ];
}; };
}; };
@ -51,70 +45,69 @@ in {
}; };
}) allDevices; }) allDevices;
services.homeAssistantConfig = { #services.homeAssistantConfig = {
light = lib.mapAttrsToList (name: # light = lib.mapAttrsToList (name:
{ ... }: { # { ... }: {
platform = "mqtt"; # platform = "mqtt";
name = name; # name = name;
state_topic = "zigbee2mqtt/${name}"; # state_topic = "zigbee2mqtt/${name}";
availability_topic = "zigbee2mqtt/bridge/state"; # availability_topic = "zigbee2mqtt/bridge/state";
command_topic = "zigbee2mqtt/${name}/set"; # command_topic = "zigbee2mqtt/${name}/set";
value_template = "{{ value_json.click }}"; # value_template = "{{ value_json.click }}";
brightness = true; # brightness = true;
color_temp = true; # color_temp = true;
schema = "json"; # schema = "json";
}) allDevices; # }) allDevices;
sensor = with lib; # sensor = with lib;
mapAttrsToList (name: # mapAttrsToList (name:
{ ... }: { # { ... }: {
name = "link_${name}"; # name = "link_${name}";
platform = "mqtt"; # platform = "mqtt";
state_topic = "zigbee2mqtt/${name}"; # state_topic = "zigbee2mqtt/${name}";
availability_topic = "zigbee2mqtt/bridge/state"; # availability_topic = "zigbee2mqtt/bridge/state";
icon = "mdi:signal"; # icon = "mdi:signal";
value_template = "{{ value_json.linkquality}}"; # value_template = "{{ value_json.linkquality}}";
}) allDevices; # }) allDevices;
binary_sensor = lib.mapAttrsToList (name: # binary_sensor = lib.mapAttrsToList (name:
{ ... }: { # { ... }: {
name = "update_${name}"; # name = "update_${name}";
platform = "mqtt"; # platform = "mqtt";
state_topic = "zigbee2mqtt/${name}"; # state_topic = "zigbee2mqtt/${name}";
availability_topic = "zigbee2mqtt/bridge/state"; # availability_topic = "zigbee2mqtt/bridge/state";
payload_on = true; # payload_on = true;
payload_off = false; # payload_off = false;
value_template = "{{ value_json.update_available }}"; # value_template = "{{ value_json.update_available }}";
}) allDevices; # }) allDevices;
# create groups # # create groups
# ------------- # # -------------
group = let # group = let
# to have nice panels for every device # # to have nice panels for every device
lightGroups = lib.mapAttrs (name: # lightGroups = lib.mapAttrs (name:
{ ... }: { # { ... }: {
control = "hidden"; # entities = [
entities = [ # "light.${name}"
"light.${name}" # "sensor.link_${name}"
"sensor.link_${name}" # "binary_sensor.update_${name}"
"binary_sensor.update_${name}" # ];
]; # }) allDevices;
}) allDevices;
# sort lights into given groups. # # sort lights into given groups.
sortedInGroups = let # sortedInGroups = let
groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name: # groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
{ groups ? [ ], ... }: # { groups ? [ ], ... }:
map (groupName: { "${groupName}" = "light.${name}"; }) groups) # map (groupName: { "${groupName}" = "light.${name}"; }) groups)
allDevices)); # allDevices));
in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries; # in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
in sortedInGroups // lightGroups // { # in sortedInGroups // lightGroups // {
all_lights.entities = # all_lights.entities =
lib.mapAttrsToList (name: { ... }: "light.${name}") allDevices; # lib.mapAttrsToList (name: { ... }: "light.${name}") allDevices;
}; # };
}; #};
} }

View file

@ -51,71 +51,63 @@ in {
}; };
}) allDevices; }) allDevices;
services.homeAssistantConfig = { #services.homeAssistantConfig = {
# # define meta information sensors
# define meta information sensors # sensor = lib.flatten (lib.mapAttrsToList (name:
sensor = lib.flatten (lib.mapAttrsToList (name: # { ... }: [
{ ... }: [ # {
{ # name = "battery_${name}";
name = "battery_${name}"; # platform = "mqtt";
platform = "mqtt"; # state_topic = "zigbee2mqtt/${name}";
state_topic = "zigbee2mqtt/${name}"; # availability_topic = "zigbee2mqtt/bridge/state";
availability_topic = "zigbee2mqtt/bridge/state"; # unit_of_measurement = "%";
unit_of_measurement = "%"; # icon = "mdi:battery-10";
icon = "mdi:battery-10"; # value_template = "{{ value_json.battery }}";
value_template = "{{ value_json.battery }}"; # }
} # {
{ # name = "link_${name}";
name = "link_${name}"; # platform = "mqtt";
platform = "mqtt"; # state_topic = "zigbee2mqtt/${name}";
state_topic = "zigbee2mqtt/${name}"; # availability_topic = "zigbee2mqtt/bridge/state";
availability_topic = "zigbee2mqtt/bridge/state"; # icon = "mdi:signal";
icon = "mdi:signal"; # unit_of_measurement = "lqi";
unit_of_measurement = "lqi"; # value_template = "{{ value_json.linkquality }}";
value_template = "{{ value_json.linkquality }}"; # }
} # ]) allDevices);
]) allDevices); # binary_sensor = lib.mapAttrsToList (name:
# { ... }: {
binary_sensor = lib.mapAttrsToList (name: # name = name;
{ ... }: { # platform = "mqtt";
name = name; # device_class = "motion";
platform = "mqtt"; # state_topic = "zigbee2mqtt/${name}";
device_class = "motion"; # availability_topic = "zigbee2mqtt/bridge/state";
state_topic = "zigbee2mqtt/${name}"; # payload_on = true;
availability_topic = "zigbee2mqtt/bridge/state"; # payload_off = false;
payload_on = true; # value_template = "{{ value_json.occupancy }}";
payload_off = false; # }) allDevices;
value_template = "{{ value_json.occupancy }}"; # # create groups
}) allDevices; # # -------------
# group = let
# create groups # # to have nice panels for every device
# ------------- # sensorGroups = lib.mapAttrs (name:
group = let # { ... }: {
# entities = [
# to have nice panels for every device # "binary_sensor.${name}"
sensorGroups = lib.mapAttrs (name: # "sensor.battery_${name}"
{ ... }: { # "sensor.link_${name}"
control = "hidden"; # ];
entities = [ # }) allDevices;
"binary_sensor.${name}" # # sort lights into given groups.
"sensor.battery_${name}" # sortedInGroups = let
"sensor.link_${name}" # groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
]; # { groups ? [ ], ... }:
}) allDevices; # map (groupName: { "${groupName}" = "binary_sensor.${name}"; }) groups)
# allDevices));
# sort lights into given groups. # in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
sortedInGroups = let # in sortedInGroups // sensorGroups // {
groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name: # all_sensors.entities =
{ groups ? [ ], ... }: # lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}") allDevices;
map (groupName: { "${groupName}" = "binary_sensor.${name}"; }) groups) # };
allDevices)); #};
in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
in sortedInGroups // sensorGroups // {
all_sensors.entities =
lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}") allDevices;
};
};
} }

View file

@ -83,7 +83,6 @@ in {
# to have nice panels for every device # to have nice panels for every device
sensorGroups = lib.mapAttrs (name: sensorGroups = lib.mapAttrs (name:
{ ... }: { { ... }: {
control = "hidden";
entities = [ entities = [
"sensor.${name}" "sensor.${name}"
"sensor.humidity_${name}" "sensor.humidity_${name}"

View file

@ -6,280 +6,32 @@ let
cfg = config.services.homeAssistantConfig; cfg = config.services.homeAssistantConfig;
mkMagicMergeOption = { description ? "", example ? { }, default ? { }, ... }:
mkOption {
inherit example description default;
type = with lib.types;
let
valueType = nullOr (oneOf [
bool
int
float
str
(attrsOf valueType)
(listOf valueType)
]) // {
description = "";
emptyValue.value = { };
};
in valueType;
};
in { in {
options.services.homeAssistantConfig = mkOption { options.services.homeAssistantConfig = mkMagicMergeOption {
default = null;
type = with types;
nullOr (submodule {
options = {
group = mkOption {
default = null;
example = {
schlafzimmer = {
view = false;
entities = [ "switch.pal01" ];
};
};
type = with types;
nullOr (attrsOf (submodule {
options = {
name = mkOption {
default = null;
type = with types; nullOr str;
description = ''
(string)(Optional)Name of the group.
'';
};
view = mkOption {
default = false;
type = with types; bool;
description = ''
(boolean)(Optional)If yes then the entry will be shown as a view (tab) at the top. Groups that are set to view: true cannot be used as entities in other views.
'';
};
icon = mkOption {
default = null;
type = with types; nullOr str;
description = ''
(string)(Optional)If the group is a view, this icon will show at the top in the frontend instead of the name. If the group is a view and both name and icon have been specified, the icon will appear at the top of the frontend and the name will be displayed as the mouse-over text. If its not a view, then the icon shows when this group is used in another group.
'';
};
control = mkOption {
default = null;
type = with types; nullOr str;
description = ''
(string)(Optional)Set value to hidden. If hidden then the group switch will be hidden.
'';
};
entities = mkOption {
default = [ ];
type = with types; listOf str;
description = ''
(list)(Required)Array or comma delimited string, list of entities to group.
'';
};
all = mkOption {
default = false;
type = with types; bool;
description = ''
(boolean)(Optional)Set this to true if the group state should only turn on if all grouped entities are on.
'';
};
};
}));
};
homeassistant = mkOption {
type = with types;
(submodule {
options = {
name = mkOption {
default = "Home";
type = with types; str;
};
time_zone = mkOption {
default = config.time.timeZone;
type = with types; str;
};
latitude = mkOption {
default = 52.464031;
type = with types; float;
};
longitude = mkOption {
default = 13.381925;
type = with types; float;
};
elevation = mkOption {
default = 34;
type = with types; int;
};
unit_system = mkOption {
default = "metric";
type = with types; str;
};
whitelist_external_dirs = mkOption {
default = null;
type = with types; nullOr (listOf str);
};
auth_providers = mkOption {
default = null;
type = with types; nullOr (listOf attrs);
};
customize = mkOption {
type = with types;
attrsOf (submodule {
options = {
friendly_name = mkOption { type = with types; str; };
entity_picture = mkOption {
default = null;
type = with types; nullOr str;
};
icon = mkOption {
default = null;
type = with types; nullOr str;
};
};
});
};
};
});
};
introduction = mkOption {
default = { };
type = with types; attrs;
};
frontend = mkOption {
default = { };
type = with types; attrs;
};
config = mkOption {
default = { };
type = with types; attrs;
};
http = mkOption {
default = null;
type = with types; nullOr attrs;
};
discovery = mkOption {
default = null;
type = with types; nullOr attrs;
};
history = mkOption {
default = null;
type = with types; nullOr attrs;
};
logbook = mkOption {
default = null;
type = with types; nullOr attrs;
};
logger = mkOption {
default = { };
type = with types; attrs;
};
lovelace = mkOption {
default = { mode = "yaml"; };
type = with types; nullOr attrs;
};
map = mkOption {
default = null;
type = with types; nullOr attrs;
};
mqtt = mkOption {
default = null;
type = with types; nullOr attrs;
};
sun = mkOption {
default = null;
type = with types; nullOr attrs;
};
switch = mkOption {
default = null;
type = with types; nullOr (listOf attrs);
};
binary_sensor = mkOption {
default = null;
type = with types; nullOr (listOf attrs);
};
light = mkOption {
default = null;
type = with types; nullOr (listOf attrs);
};
sensor = mkOption {
default = null;
type = with types; nullOr (listOf attrs);
};
prometheus = mkOption {
default = null;
type = with types; nullOr attrs;
};
automation = mkOption {
default = null;
type = with types; nullOr (listOf attrs);
};
media_player = mkOption {
default = null;
type = with types; nullOr (listOf attrs);
};
mysensors = mkOption {
default = null;
type = with types; nullOr attrs;
};
script = mkOption {
default = null;
type = with types;
nullOr (attrsOf (submodule {
options = {
alias = mkOption {
default = null;
type = with types; nullOr str;
};
sequence = mkOption {
default = [ ];
type = with types; listOf attrs;
};
};
}));
};
input_number = mkOption {
default = null;
type = with types; nullOr (attrsOf attrs);
};
input_text = mkOption {
default = null;
type = with types; nullOr (attrsOf attrs);
};
input_select = mkOption {
default = null;
type = with types; nullOr (attrsOf attrs);
};
input_boolean = mkOption {
default = null;
type = with types; nullOr (attrsOf attrs);
};
input_datetime = mkOption {
default = null;
type = with types; nullOr (attrsOf attrs);
};
calendar = mkOption {
default = [ ];
type = with types; listOf attrs;
};
shell_command = mkOption {
default = null;
type = with types; nullOr (attrsOf str);
};
};
});
description = '' description = ''
home-assistant configuration home-assistant configuration
''; '';
}; };
config = mkIf (cfg != null) { config = mkIf (cfg != null) { services.home-assistant.config = cfg; };
services.home-assistant.config = let
sanitize = configuration:
lib.getAttr (builtins.typeOf configuration) {
bool = configuration;
int = configuration;
string = configuration;
str = configuration;
float = configuration;
list = map sanitize configuration;
set = let
stripped = lib.flip lib.filterAttrs configuration (name: value:
name != "_module" && name != "_ref" && value != null);
recursiveSanitized = lib.mapAttrs (lib.const sanitize) stripped;
in if (length (attrNames configuration) == 0) then
null
else
recursiveSanitized;
};
in sanitize cfg;
};
} }