hass: configure fyrtur and batteries
This commit is contained in:
parent
49574ee6ec
commit
902df4d118
10 changed files with 260 additions and 347 deletions
|
@ -152,7 +152,6 @@ in {
|
|||
};
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
alias = "Set Scene To Outside when opening door";
|
||||
trigger = [
|
||||
|
@ -179,68 +178,88 @@ in {
|
|||
};
|
||||
};
|
||||
}
|
||||
|
||||
# window roles
|
||||
{
|
||||
alias = "windows down in the evening";
|
||||
trigger = [{
|
||||
platform = "sun";
|
||||
event = "sunset";
|
||||
offset = "+00:10:00"; # 10 min after sunset
|
||||
offset = "+00:01:00"; # 10 min after sunset
|
||||
}];
|
||||
action = [
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur1/set";
|
||||
topic = "zigbee2mqtt/fyrtur1/set"; # office
|
||||
payload_template = ''{"position":"15"}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur2/set";
|
||||
topic = "zigbee2mqtt/fyrtur2/set"; # office
|
||||
payload_template = ''{"position":"15"}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur3/set";
|
||||
payload_template = ''{"position":"21"}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur4/set";
|
||||
payload_template = ''{"position":"21"}'';
|
||||
};
|
||||
}
|
||||
];
|
||||
}
|
||||
{
|
||||
alias = "windows up in the morning";
|
||||
trigger = [{
|
||||
platform = "sun";
|
||||
event = "sunrise";
|
||||
offset = "-00:3:00"; # 3 min before sunrise
|
||||
platform = "time";
|
||||
at = "09:00:00";
|
||||
}];
|
||||
action = [{
|
||||
action = [
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur1/set";
|
||||
payload_template = ''{"position":"90"}'';
|
||||
};
|
||||
}];
|
||||
}
|
||||
{
|
||||
alias = "windows up in the morning";
|
||||
trigger = [{
|
||||
platform = "sun";
|
||||
event = "sunrise";
|
||||
offset = "+02:30:00"; # 2 1/2 hours after sunrise
|
||||
}];
|
||||
action = [{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur3/set";
|
||||
payload_template = ''{"position":"99"}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur4/set";
|
||||
payload_template = ''{"position":"99"}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/fyrtur2/set";
|
||||
payload_template = ''{"position":"90"}'';
|
||||
};
|
||||
}];
|
||||
}
|
||||
|
||||
];
|
||||
}
|
||||
# heater
|
||||
{
|
||||
alias = "heater on in the morning";
|
||||
trigger = [{
|
||||
platform = "time";
|
||||
at = "09:30:00";
|
||||
at = "09:00:00";
|
||||
}];
|
||||
action = [
|
||||
{
|
||||
|
@ -248,7 +267,7 @@ in {
|
|||
data_template = {
|
||||
topic = "zigbee2mqtt/heater1/set"; # office
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":21.5}'';
|
||||
''{"system_mode":"auto","current_heating_setpoint":21.0}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
|
@ -256,7 +275,7 @@ in {
|
|||
data_template = {
|
||||
topic = "zigbee2mqtt/heater2/set"; # office
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":21.5}'';
|
||||
''{"system_mode":"auto","current_heating_setpoint":21.0}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
|
@ -264,7 +283,7 @@ in {
|
|||
data_template = {
|
||||
topic = "zigbee2mqtt/heater3/set"; # bed room
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":20.0}'';
|
||||
''{"system_mode":"auto","current_heating_setpoint":19.0}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
|
@ -272,12 +291,52 @@ in {
|
|||
data_template = {
|
||||
topic = "zigbee2mqtt/heater4/set"; # storage room
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":18.0}'';
|
||||
''{"system_mode":"auto","current_heating_setpoint":19.0}'';
|
||||
};
|
||||
}
|
||||
];
|
||||
}
|
||||
{
|
||||
alias = "heater up in the early evening";
|
||||
trigger = [{
|
||||
platform = "time";
|
||||
at = "19:45:00";
|
||||
}];
|
||||
action = [
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/heater1/set"; # office
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":24.0}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/heater2/set"; # office
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":24.0}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/heater3/set"; # bed room
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":24.0}'';
|
||||
};
|
||||
}
|
||||
{
|
||||
service = "mqtt.publish";
|
||||
data_template = {
|
||||
topic = "zigbee2mqtt/heater4/set"; # storage room
|
||||
payload_template =
|
||||
''{"system_mode":"auto","current_heating_setpoint":19.0}'';
|
||||
};
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
{
|
||||
alias = "heater off in the evening";
|
||||
trigger = [{
|
||||
|
|
|
@ -106,8 +106,9 @@
|
|||
delay = delay;
|
||||
command = {
|
||||
# Configure it once to the color you like
|
||||
# {"state":"{{state}}","brightness":{{brightness}},"color":{"hex":"#FFFFFF}}
|
||||
command = ''{"state":"{{state}}","brightness":{{brightness}}}'';
|
||||
# {"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";
|
||||
|
@ -131,6 +132,10 @@
|
|||
topic = "zigbee2mqtt/light_7";
|
||||
rooms = [ "sleeping_room" ];
|
||||
})
|
||||
(led {
|
||||
topic = "zigbee2mqtt/led_1";
|
||||
rooms = [ "office_room" ];
|
||||
})
|
||||
(led {
|
||||
topic = "zigbee2mqtt/led_2";
|
||||
rooms = [ "kitchen" ];
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
./mqtt.nix
|
||||
./zigbee2mqtt/buttons.nix
|
||||
./zigbee2mqtt/doors.nix
|
||||
./zigbee2mqtt/fyrtur.nix
|
||||
./zigbee2mqtt/heater.nix
|
||||
./zigbee2mqtt/leds.nix
|
||||
./zigbee2mqtt/lights.nix
|
||||
|
@ -10,7 +11,6 @@
|
|||
./zigbee2mqtt/repeater.nix
|
||||
./zigbee2mqtt/service.nix
|
||||
./zigbee2mqtt/temperatur.nix
|
||||
./zigbee2mqtt/windows.nix
|
||||
];
|
||||
|
||||
services.zigbee2mqtt = {
|
||||
|
|
|
@ -11,19 +11,19 @@ let
|
|||
allDevices = {
|
||||
"button_1" = {
|
||||
id = "0x00158d0002b04f65";
|
||||
groups = [ "living_room" ];
|
||||
#groups = [ "living_room" ];
|
||||
states.single = "input_boolean.situation_toggle";
|
||||
states.hold = "input_boolean.printer_toggle";
|
||||
};
|
||||
"button_2" = {
|
||||
id = "0x00158d0002b04f09";
|
||||
groups = [ "bed_room" ];
|
||||
#groups = [ "bed_room" ];
|
||||
states.single = "input_boolean.situation_toggle";
|
||||
states.hold = "input_boolean.printer_toggle";
|
||||
};
|
||||
"button_3" = {
|
||||
id = "0x00158d0002b00e04";
|
||||
groups = [ "bed_room" ];
|
||||
#groups = [ "bed_room" ];
|
||||
states.single = "input_boolean.situation_toggle";
|
||||
states.hold = "input_boolean.printer_toggle";
|
||||
};
|
||||
|
@ -107,41 +107,37 @@ in {
|
|||
|
||||
# create groups
|
||||
# -------------
|
||||
group = let
|
||||
|
||||
# to have nice panels for every device
|
||||
sensorGroups = lib.mapAttrs (name:
|
||||
{ states ? { }, ... }:
|
||||
let
|
||||
entityIds = { single ? "input_boolean.single_${name}"
|
||||
, double ? "input_boolean.double_${name}"
|
||||
, hold ? "input_boolean.hold_${name}", ... }: [
|
||||
single
|
||||
double
|
||||
hold
|
||||
];
|
||||
in {
|
||||
entities = [ "sensor.${name}" ] ++ (entityIds states)
|
||||
++ [ "sensor.battery_${name}" "sensor.link_${name}" ];
|
||||
}) allDevices;
|
||||
|
||||
# sort lights into given groups.
|
||||
sortedInGroups = let
|
||||
groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
||||
{ groups ? [ ], states ? { }, ... }:
|
||||
map (groupName: {
|
||||
"${groupName}" = if (lib.hasAttr "single" states) then
|
||||
states.single
|
||||
else
|
||||
"input_boolean.single_${name}";
|
||||
}) groups) allDevices));
|
||||
in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
||||
|
||||
in sortedInGroups // sensorGroups // {
|
||||
|
||||
all_sensors.entities =
|
||||
lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}") allDevices;
|
||||
};
|
||||
#group = let
|
||||
# # to have nice panels for every device
|
||||
# sensorGroups = lib.mapAttrs (name:
|
||||
# { states ? { }, ... }:
|
||||
# let
|
||||
# entityIds = { single ? "input_boolean.single_${name}"
|
||||
# , double ? "input_boolean.double_${name}"
|
||||
# , hold ? "input_boolean.hold_${name}", ... }: [
|
||||
# single
|
||||
# double
|
||||
# hold
|
||||
# ];
|
||||
# in {
|
||||
# entities = [ "sensor.${name}" ] ++ (entityIds states)
|
||||
# ++ [ "sensor.battery_${name}" "sensor.link_${name}" ];
|
||||
# }) allDevices;
|
||||
# # sort lights into given groups.
|
||||
# sortedInGroups = let
|
||||
# groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
||||
# { groups ? [ ], states ? { }, ... }:
|
||||
# map (groupName: {
|
||||
# "${groupName}" = if (lib.hasAttr "single" states) then
|
||||
# states.single
|
||||
# else
|
||||
# "input_boolean.single_${name}";
|
||||
# }) groups) allDevices));
|
||||
# in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
||||
#in sortedInGroups // sensorGroups // {
|
||||
# all_sensors.entities =
|
||||
# lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}") allDevices;
|
||||
#};
|
||||
|
||||
# create automation
|
||||
# -----------------
|
||||
|
|
52
configs/pepe/home-assistant/zigbee2mqtt/fyrtur.nix
Normal file
52
configs/pepe/home-assistant/zigbee2mqtt/fyrtur.nix
Normal file
|
@ -0,0 +1,52 @@
|
|||
{ pkgs, lib, ... }:
|
||||
let
|
||||
|
||||
# https://www.zigbee2mqtt.io/devices/E1757.html
|
||||
allDevices = {
|
||||
"fyrtur1" = { id = "0x680ae2fffe64fa40"; }; # office
|
||||
"fyrtur2" = { id = "0x680ae2fffe6e9f41"; }; # bed room
|
||||
"fyrtur3" = { id = "0x680ae2fffe8f6411"; }; # office (close to kitchen)
|
||||
"fyrtur4" = { id = "0x680ae2fffe91d234"; }; # kitchen
|
||||
};
|
||||
|
||||
# -t "zigbee2mqtt/fyrtur1/set" -m '{"position":100}'
|
||||
# -t "zigbee2mqtt/fyrtur1/set" -m '{"position":15}'
|
||||
in {
|
||||
|
||||
services.zigbee2mqtt.devices = lib.mapAttrs' (name:
|
||||
{ id, ... }: {
|
||||
name = id;
|
||||
value = {
|
||||
retain = false;
|
||||
friendly_name = name;
|
||||
transition = 0.1;
|
||||
};
|
||||
}) allDevices;
|
||||
|
||||
services.homeAssistantConfig = {
|
||||
|
||||
sensor = lib.flatten (lib.mapAttrsToList (name:
|
||||
{ ... }: [
|
||||
{
|
||||
name = "battery_${name}";
|
||||
platform = "mqtt";
|
||||
state_topic = "zigbee2mqtt/${name}";
|
||||
availability_topic = "zigbee2mqtt/bridge/state";
|
||||
unit_of_measurement = "%";
|
||||
icon = "mdi:battery-10";
|
||||
value_template = "{{ value_json.battery }}";
|
||||
}
|
||||
{
|
||||
name = "link_${name}";
|
||||
platform = "mqtt";
|
||||
state_topic = "zigbee2mqtt/${name}";
|
||||
availability_topic = "zigbee2mqtt/bridge/state";
|
||||
icon = "mdi:signal";
|
||||
unit_of_measurement = "lqi";
|
||||
value_template = "{{ value_json.linkquality }}";
|
||||
}
|
||||
]) allDevices);
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -26,83 +26,27 @@ in {
|
|||
|
||||
services.homeAssistantConfig = {
|
||||
|
||||
#light = lib.flatten (lib.mapAttrsToList (name:
|
||||
# { ... }: [
|
||||
# {
|
||||
# name = "rgb_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# brightness = true;
|
||||
# color_temp = true;
|
||||
# xy = true;
|
||||
# schema = "json";
|
||||
# command_topic = "zigbee2mqtt/${name}/rgb/set";
|
||||
# brightness_scale = 254;
|
||||
# state_topic_postfix = "rgb";
|
||||
# }
|
||||
# {
|
||||
# name = "white_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# brightness = true;
|
||||
# schema = "json";
|
||||
# command_topic = "zigbee2mqtt/${name}/white/set";
|
||||
# brightness_scale = 254;
|
||||
# state_topic_postfix = "white";
|
||||
# }
|
||||
# ]) allDevices);
|
||||
|
||||
#sensor = with lib;
|
||||
# mapAttrsToList (name:
|
||||
# { ... }: {
|
||||
# name = "link_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# icon = "mdi:signal";
|
||||
# unit_of_measurement = "lqi";
|
||||
# value_template = "{{ value_json.linkquality}}";
|
||||
# }) allDevices;
|
||||
|
||||
# binary_sensor = lib.mapAttrsToList (name:
|
||||
# { ... }: {
|
||||
# name = "update_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# payload_on = true;
|
||||
# payload_off = false;
|
||||
# value_template = "{{ value_json.update_available }}";
|
||||
# }) allDevices;
|
||||
|
||||
# # create groups
|
||||
# # -------------
|
||||
# group = let
|
||||
|
||||
# # to have nice panels for every device
|
||||
# lightGroups = lib.mapAttrs (name:
|
||||
# { ... }: {
|
||||
# entities = [
|
||||
# "light.${name}"
|
||||
# "sensor.link_${name}"
|
||||
# "binary_sensor.update_${name}"
|
||||
# ];
|
||||
# }) allDevices;
|
||||
|
||||
# # sort lights into given groups.
|
||||
# sortedInGroups = let
|
||||
# groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
||||
# { groups ? [ ], ... }:
|
||||
# map (groupName: { "${groupName}" = "light.${name}"; }) groups)
|
||||
# allDevices));
|
||||
# in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
||||
|
||||
# in sortedInGroups // lightGroups // {
|
||||
# all_lights.entities =
|
||||
# lib.mapAttrsToList (name: { ... }: "light.${name}") allDevices;
|
||||
# };
|
||||
sensor = lib.flatten (lib.mapAttrsToList (name:
|
||||
{ ... }: [
|
||||
{
|
||||
name = "battery_${name}";
|
||||
platform = "mqtt";
|
||||
state_topic = "zigbee2mqtt/${name}";
|
||||
availability_topic = "zigbee2mqtt/bridge/state";
|
||||
unit_of_measurement = "%";
|
||||
icon = "mdi:battery-10";
|
||||
value_template = "{{ value_json.battery }}";
|
||||
}
|
||||
{
|
||||
name = "link_${name}";
|
||||
platform = "mqtt";
|
||||
state_topic = "zigbee2mqtt/${name}";
|
||||
availability_topic = "zigbee2mqtt/bridge/state";
|
||||
icon = "mdi:signal";
|
||||
unit_of_measurement = "lqi";
|
||||
value_template = "{{ value_json.linkquality }}";
|
||||
}
|
||||
]) allDevices);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ let
|
|||
"led_2" = { id = "0x00124b001ee958b3"; };
|
||||
};
|
||||
|
||||
# -t "zigbee2mqtt/led_1/set" -m '{"state":"ON","transition":0, "color_temp":255}'
|
||||
# -t "zigbee2mqtt/led_1/set" -m '{"state":"OFF","transition":0, "color_temp":255}'
|
||||
# -t "zigbee2mqtt/led_1/set" -m '{"state":"ON","brightness":255,"color":{"hex":"#00FFFF"}}'
|
||||
# -t "zigbee2mqtt/led_1/set" -m '{"state":"OFF"}'
|
||||
in {
|
||||
|
|
|
@ -51,63 +51,28 @@ in {
|
|||
};
|
||||
}) allDevices;
|
||||
|
||||
#services.homeAssistantConfig = {
|
||||
# # define meta information sensors
|
||||
# sensor = lib.flatten (lib.mapAttrsToList (name:
|
||||
# { ... }: [
|
||||
# {
|
||||
# name = "battery_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# unit_of_measurement = "%";
|
||||
# icon = "mdi:battery-10";
|
||||
# value_template = "{{ value_json.battery }}";
|
||||
# }
|
||||
# {
|
||||
# name = "link_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# icon = "mdi:signal";
|
||||
# unit_of_measurement = "lqi";
|
||||
# value_template = "{{ value_json.linkquality }}";
|
||||
# }
|
||||
# ]) allDevices);
|
||||
# binary_sensor = lib.mapAttrsToList (name:
|
||||
# { ... }: {
|
||||
# name = name;
|
||||
# platform = "mqtt";
|
||||
# device_class = "motion";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# payload_on = true;
|
||||
# payload_off = false;
|
||||
# value_template = "{{ value_json.occupancy }}";
|
||||
# }) allDevices;
|
||||
# # create groups
|
||||
# # -------------
|
||||
# group = let
|
||||
# # to have nice panels for every device
|
||||
# sensorGroups = lib.mapAttrs (name:
|
||||
# { ... }: {
|
||||
# entities = [
|
||||
# "binary_sensor.${name}"
|
||||
# "sensor.battery_${name}"
|
||||
# "sensor.link_${name}"
|
||||
# ];
|
||||
# }) allDevices;
|
||||
# # sort lights into given groups.
|
||||
# sortedInGroups = let
|
||||
# groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
||||
# { groups ? [ ], ... }:
|
||||
# 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;
|
||||
# };
|
||||
#};
|
||||
|
||||
services.homeAssistantConfig = {
|
||||
# define meta information sensors
|
||||
sensor = lib.flatten (lib.mapAttrsToList (name:
|
||||
{ ... }: [
|
||||
{
|
||||
name = "battery_${name}";
|
||||
platform = "mqtt";
|
||||
state_topic = "zigbee2mqtt/${name}";
|
||||
availability_topic = "zigbee2mqtt/bridge/state";
|
||||
unit_of_measurement = "%";
|
||||
icon = "mdi:battery-10";
|
||||
value_template = "{{ value_json.battery }}";
|
||||
}
|
||||
{
|
||||
name = "link_${name}";
|
||||
platform = "mqtt";
|
||||
state_topic = "zigbee2mqtt/${name}";
|
||||
availability_topic = "zigbee2mqtt/bridge/state";
|
||||
icon = "mdi:signal";
|
||||
unit_of_measurement = "lqi";
|
||||
value_template = "{{ value_json.linkquality }}";
|
||||
}
|
||||
]) allDevices);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -78,34 +78,30 @@ in {
|
|||
|
||||
# create groups
|
||||
# -------------
|
||||
group = let
|
||||
#group = let
|
||||
# # to have nice panels for every device
|
||||
# sensorGroups = lib.mapAttrs (name:
|
||||
# { ... }: {
|
||||
# entities = [
|
||||
# "sensor.${name}"
|
||||
# "sensor.humidity_${name}"
|
||||
# #"sensor.pressure_${name}"
|
||||
# "sensor.battery_${name}"
|
||||
# "sensor.link_${name}"
|
||||
# ];
|
||||
# }) allDevices;
|
||||
# # sort lights into given groups.
|
||||
# sortedInGroups = let
|
||||
# groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
||||
# { groups ? [ ], ... }:
|
||||
# map (groupName: { "${groupName}" = "sensor.${name}"; }) groups)
|
||||
# allDevices));
|
||||
# in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
||||
#in sortedInGroups // sensorGroups // {
|
||||
# all_sensors.entities =
|
||||
# lib.mapAttrsToList (name: { ... }: "sensor.${name}") allDevices;
|
||||
#};
|
||||
|
||||
# to have nice panels for every device
|
||||
sensorGroups = lib.mapAttrs (name:
|
||||
{ ... }: {
|
||||
entities = [
|
||||
"sensor.${name}"
|
||||
"sensor.humidity_${name}"
|
||||
#"sensor.pressure_${name}"
|
||||
"sensor.battery_${name}"
|
||||
"sensor.link_${name}"
|
||||
|
||||
];
|
||||
}) allDevices;
|
||||
|
||||
# sort lights into given groups.
|
||||
sortedInGroups = let
|
||||
groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
||||
{ groups ? [ ], ... }:
|
||||
map (groupName: { "${groupName}" = "sensor.${name}"; }) groups)
|
||||
allDevices));
|
||||
in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
||||
|
||||
in sortedInGroups // sensorGroups // {
|
||||
|
||||
all_sensors.entities =
|
||||
lib.mapAttrsToList (name: { ... }: "sensor.${name}") allDevices;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
{ pkgs, lib, ... }:
|
||||
let
|
||||
|
||||
# https://www.zigbee2mqtt.io/devices/E1757.html
|
||||
allDevices = {
|
||||
"fyrtur1" = { id = "0x680ae2fffe64fa40"; }; # office
|
||||
"fyrtur2" = { id = "0x680ae2fffe6e9f41"; }; # sleeping room
|
||||
};
|
||||
|
||||
# -t "zigbee2mqtt/fyrtur1/set" -m '{"position":100}'
|
||||
# -t "zigbee2mqtt/fyrtur1/set" -m '{"position":15}'
|
||||
in {
|
||||
|
||||
services.zigbee2mqtt.devices = lib.mapAttrs' (name:
|
||||
{ id, ... }: {
|
||||
name = id;
|
||||
value = {
|
||||
retain = false;
|
||||
friendly_name = name;
|
||||
transition = 1;
|
||||
};
|
||||
}) allDevices;
|
||||
|
||||
services.homeAssistantConfig = {
|
||||
|
||||
#light = lib.flatten (lib.mapAttrsToList (name:
|
||||
# { ... }: [
|
||||
# {
|
||||
# name = "rgb_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# brightness = true;
|
||||
# color_temp = true;
|
||||
# xy = true;
|
||||
# schema = "json";
|
||||
# command_topic = "zigbee2mqtt/${name}/rgb/set";
|
||||
# brightness_scale = 254;
|
||||
# state_topic_postfix = "rgb";
|
||||
# }
|
||||
# {
|
||||
# name = "white_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# brightness = true;
|
||||
# schema = "json";
|
||||
# command_topic = "zigbee2mqtt/${name}/white/set";
|
||||
# brightness_scale = 254;
|
||||
# state_topic_postfix = "white";
|
||||
# }
|
||||
# ]) allDevices);
|
||||
|
||||
#sensor = with lib;
|
||||
# mapAttrsToList (name:
|
||||
# { ... }: {
|
||||
# name = "link_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# icon = "mdi:signal";
|
||||
# unit_of_measurement = "lqi";
|
||||
# value_template = "{{ value_json.linkquality}}";
|
||||
# }) allDevices;
|
||||
|
||||
# binary_sensor = lib.mapAttrsToList (name:
|
||||
# { ... }: {
|
||||
# name = "update_${name}";
|
||||
# platform = "mqtt";
|
||||
# state_topic = "zigbee2mqtt/${name}";
|
||||
# availability_topic = "zigbee2mqtt/bridge/state";
|
||||
# payload_on = true;
|
||||
# payload_off = false;
|
||||
# value_template = "{{ value_json.update_available }}";
|
||||
# }) allDevices;
|
||||
|
||||
# # create groups
|
||||
# # -------------
|
||||
# group = let
|
||||
|
||||
# # to have nice panels for every device
|
||||
# lightGroups = lib.mapAttrs (name:
|
||||
# { ... }: {
|
||||
# entities = [
|
||||
# "light.${name}"
|
||||
# "sensor.link_${name}"
|
||||
# "binary_sensor.update_${name}"
|
||||
# ];
|
||||
# }) allDevices;
|
||||
|
||||
# # sort lights into given groups.
|
||||
# sortedInGroups = let
|
||||
# groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
||||
# { groups ? [ ], ... }:
|
||||
# map (groupName: { "${groupName}" = "light.${name}"; }) groups)
|
||||
# allDevices));
|
||||
# in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
||||
|
||||
# in sortedInGroups // lightGroups // {
|
||||
# all_lights.entities =
|
||||
# lib.mapAttrsToList (name: { ... }: "light.${name}") allDevices;
|
||||
# };
|
||||
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue