pepe: merged buttons in bed room
This commit is contained in:
parent
98f6fd8eea
commit
700c7c4939
2 changed files with 141 additions and 92 deletions
|
@ -33,6 +33,8 @@ in {
|
||||||
|
|
||||||
prometheus.namespace = "hass";
|
prometheus.namespace = "hass";
|
||||||
|
|
||||||
|
input_boolean.bed_room_buttons.icon = "mdi:toggle-switch";
|
||||||
|
|
||||||
automation = let
|
automation = let
|
||||||
# todo : at night only turn trigger essential groups
|
# todo : at night only turn trigger essential groups
|
||||||
presents = room_group: present_group: [
|
presents = room_group: present_group: [
|
||||||
|
@ -71,7 +73,7 @@ in {
|
||||||
];
|
];
|
||||||
|
|
||||||
group = let
|
group = let
|
||||||
create_room = { name, description }: {
|
create_room = { name, description, presentEntities ? [ ] }: {
|
||||||
"${name}" = {
|
"${name}" = {
|
||||||
name = description;
|
name = description;
|
||||||
view = false;
|
view = false;
|
||||||
|
@ -81,6 +83,7 @@ in {
|
||||||
control = "hidden";
|
control = "hidden";
|
||||||
name = "${description} Anwesend";
|
name = "${description} Anwesend";
|
||||||
view = false;
|
view = false;
|
||||||
|
entities = presentEntities;
|
||||||
};
|
};
|
||||||
"${name}_essential" = {
|
"${name}_essential" = {
|
||||||
control = "hidden";
|
control = "hidden";
|
||||||
|
|
|
@ -11,15 +11,20 @@ let
|
||||||
buttons = {
|
buttons = {
|
||||||
"button_1" = {
|
"button_1" = {
|
||||||
id = "0x00158d0002b04f65";
|
id = "0x00158d0002b04f65";
|
||||||
|
# room = "living_room"; # is where it actually is placed (optional) (default "unknown")
|
||||||
|
# presents = "living_room_present" # presents group to append (optional) (default "unknown")
|
||||||
|
# states = { click = "input_boolean.living_room_button"; } # input state to hold (optional) (default "input_boolean.single_${name}")
|
||||||
room = "living_room_present";
|
room = "living_room_present";
|
||||||
};
|
};
|
||||||
"button_2" = {
|
"button_2" = {
|
||||||
id = "0x00158d0002b04f09";
|
id = "0x00158d0002b04f09";
|
||||||
room = "bed_room_present";
|
room = "bed_room_present";
|
||||||
|
states.single = "input_boolean.bed_room_buttons";
|
||||||
};
|
};
|
||||||
"button_3" = {
|
"button_3" = {
|
||||||
id = "0x00158d0002b00e04";
|
id = "0x00158d0002b00e04";
|
||||||
room = "bed_room_present";
|
room = "bed_room_present";
|
||||||
|
states.single = "input_boolean.bed_room_buttons";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
temperature = {
|
temperature = {
|
||||||
|
@ -65,9 +70,15 @@ let
|
||||||
};
|
};
|
||||||
door = {
|
door = {
|
||||||
"door_sensor_1" = { id = "0x00158d000312dc52"; };
|
"door_sensor_1" = { id = "0x00158d000312dc52"; };
|
||||||
"door_sensor_2" = { id = "0x00158d000316d5bf"; };
|
"door_sensor_2" = {
|
||||||
|
id = "0x00158d000316d5bf";
|
||||||
|
room = "floor_room_present";
|
||||||
|
};
|
||||||
"door_sensor_3" = { id = "0x00158d0002f9516f"; };
|
"door_sensor_3" = { id = "0x00158d0002f9516f"; };
|
||||||
"door_sensor_4" = { id = "0x00158d00031383b9"; };
|
"door_sensor_4" = {
|
||||||
|
id = "0x00158d00031383b9";
|
||||||
|
room = "floor_room_present";
|
||||||
|
};
|
||||||
"door_sensor_5" = { id = "0x00158d0003120d3e"; };
|
"door_sensor_5" = { id = "0x00158d0003120d3e"; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -122,21 +133,22 @@ in {
|
||||||
# define input_boolean
|
# define input_boolean
|
||||||
# --------------------
|
# --------------------
|
||||||
# which get toggled by the buttons
|
# which get toggled by the buttons
|
||||||
input_boolean = builtins.listToAttrs (lib.flatten (lib.mapAttrsToList (name:
|
input_boolean = let stripEmpty = lib.filter (a: a != { });
|
||||||
{ ... }: [
|
in builtins.listToAttrs (stripEmpty (lib.flatten (lib.mapAttrsToList (name:
|
||||||
{
|
{ states ? { }, ... }: [
|
||||||
|
(lib.optionalAttrs (!lib.hasAttr "single" states) {
|
||||||
name = "single_${name}";
|
name = "single_${name}";
|
||||||
value = { icon = "mdi:radiobox-blank"; };
|
value = { icon = "mdi:toggle-switch"; };
|
||||||
}
|
})
|
||||||
{
|
(lib.optionalAttrs (!lib.hasAttr "double" states) {
|
||||||
name = "double_${name}";
|
name = "double_${name}";
|
||||||
value = { icon = "mdi:radiobox-blank"; };
|
value = { icon = "mdi:toggle-switch"; };
|
||||||
}
|
})
|
||||||
{
|
(lib.optionalAttrs (!lib.hasAttr "hold" states) {
|
||||||
name = "hold_${name}";
|
name = "hold_${name}";
|
||||||
value = { icon = "mdi:radiobox-blank"; };
|
value = { icon = "mdi:toggle-switch"; };
|
||||||
}
|
})
|
||||||
]) sensors.buttons));
|
]) sensors.buttons)));
|
||||||
|
|
||||||
# define sensors
|
# define sensors
|
||||||
# --------------
|
# --------------
|
||||||
|
@ -254,16 +266,21 @@ in {
|
||||||
information = name: [ "sensor.battery_${name}" "sensor.link_${name}" ];
|
information = name: [ "sensor.battery_${name}" "sensor.link_${name}" ];
|
||||||
|
|
||||||
sensorButtons = lib.mapAttrs' (name:
|
sensorButtons = 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 {
|
||||||
name = name;
|
name = name;
|
||||||
value = {
|
value = {
|
||||||
control = "hidden";
|
control = "hidden";
|
||||||
entities = [
|
entities = [ "sensor.${name}" ] ++ (entityIds states)
|
||||||
"sensor.${name}"
|
++ (information name);
|
||||||
"input_boolean.single_${name}"
|
|
||||||
"input_boolean.double_${name}"
|
|
||||||
"input_boolean.hold_${name}"
|
|
||||||
] ++ (information name);
|
|
||||||
};
|
};
|
||||||
}) (sensors.buttons);
|
}) (sensors.buttons);
|
||||||
|
|
||||||
|
@ -308,33 +325,41 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# todo : make this more generic
|
# sort sensors in room groups
|
||||||
# append to *_room_present group
|
# ---------------------------
|
||||||
flatMotionSensors =
|
allRoomsGroups = let
|
||||||
|
createGroupEntities = { sensors, entityNameing }:
|
||||||
|
let
|
||||||
|
flatSensors =
|
||||||
lib.mapAttrsToList (name: values: { name = name; } // values)
|
lib.mapAttrsToList (name: values: { name = name; } // values)
|
||||||
sensors.motion;
|
sensors;
|
||||||
motionAllRooms' =
|
allRooms' =
|
||||||
lib.groupBy ({ room ? "unknown", ... }: room) flatMotionSensors;
|
lib.groupBy ({ room ? "unknown", ... }: room) flatSensors;
|
||||||
motionAllRooms = lib.mapAttrs
|
allRooms =
|
||||||
(_: devices: map ({ name, ... }: "binary_sensor.${name}") devices)
|
lib.mapAttrs (_: devices: map entityNameing devices) allRooms';
|
||||||
motionAllRooms';
|
in allRooms;
|
||||||
|
groupEntries = {
|
||||||
|
motionGroups = createGroupEntities {
|
||||||
|
sensors = sensors.motion;
|
||||||
|
entityNameing = ({ name, ... }: "binary_sensor.${name}");
|
||||||
|
};
|
||||||
|
buttonGroups = createGroupEntities {
|
||||||
|
sensors = sensors.buttons;
|
||||||
|
entityNameing = ({ name
|
||||||
|
, states ? { single = "input_boolean.single_${name}"; }, ... }:
|
||||||
|
states.single);
|
||||||
|
};
|
||||||
|
doorGroups = createGroupEntities {
|
||||||
|
sensors = sensors.door;
|
||||||
|
entityNameing = ({ name, ... }: "binary_sensor.${name}");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# todo : make this more generic
|
# merge all group entries
|
||||||
# append to *_room_present group
|
in lib.mapAttrs (_: entities: { entities = lib.flatten entities; })
|
||||||
flatButtonSensors =
|
(lib.zipAttrs (builtins.attrValues groupEntries));
|
||||||
lib.mapAttrsToList (name: values: { name = name; } // values)
|
|
||||||
sensors.buttons;
|
|
||||||
buttonAllRooms' =
|
|
||||||
lib.groupBy ({ room ? "unknown", ... }: room) flatButtonSensors;
|
|
||||||
buttonAllRooms = lib.mapAttrs (_: devices:
|
|
||||||
map ({ name, ... }: "input_boolean.single_${name}") devices)
|
|
||||||
buttonAllRooms';
|
|
||||||
|
|
||||||
presentsAllRooms =
|
in views // allRoomsGroups // sensorButtons // sensorMotions
|
||||||
lib.mapAttrs (_: entities: { entities = lib.flatten entities; })
|
|
||||||
(lib.zipAttrs [ buttonAllRooms motionAllRooms ]);
|
|
||||||
|
|
||||||
in views // presentsAllRooms // sensorButtons // sensorMotions
|
|
||||||
// sensorTemperature // sensorDoors // {
|
// sensorTemperature // sensorDoors // {
|
||||||
all_sensors.entities =
|
all_sensors.entities =
|
||||||
(lib.mapAttrsToList (name: { ... }: "sensor.${name}")
|
(lib.mapAttrsToList (name: { ... }: "sensor.${name}")
|
||||||
|
@ -348,11 +373,18 @@ in {
|
||||||
automation = let
|
automation = let
|
||||||
|
|
||||||
# single click
|
# single click
|
||||||
toggle_single_button_input = map (button: {
|
toggle_single_button_input = lib.mapAttrsToList (name:
|
||||||
alias = "toggle hold ${button}";
|
{ states ? { }, ... }:
|
||||||
|
let
|
||||||
|
entityId = if (lib.hasAttr "single" states) then
|
||||||
|
states.single
|
||||||
|
else
|
||||||
|
"input_boolean.single_${name}";
|
||||||
|
in {
|
||||||
|
alias = "toggle single click ${name}";
|
||||||
trigger = {
|
trigger = {
|
||||||
platform = "mqtt";
|
platform = "mqtt";
|
||||||
topic = "zigbee2mqtt/${button}";
|
topic = "zigbee2mqtt/${name}";
|
||||||
};
|
};
|
||||||
condition = {
|
condition = {
|
||||||
condition = "template";
|
condition = "template";
|
||||||
|
@ -360,16 +392,23 @@ in {
|
||||||
};
|
};
|
||||||
action = {
|
action = {
|
||||||
service = "input_boolean.toggle";
|
service = "input_boolean.toggle";
|
||||||
data.entity_id = "input_boolean.single_${button}";
|
data.entity_id = entityId;
|
||||||
};
|
};
|
||||||
}) (builtins.attrNames sensors.buttons);
|
}) sensors.buttons;
|
||||||
|
|
||||||
# double click
|
# double click
|
||||||
toggle_double_button_input = map (button: {
|
toggle_double_button_input = lib.mapAttrsToList (name:
|
||||||
alias = "toggle hold ${button}";
|
{ states ? { }, ... }:
|
||||||
|
let
|
||||||
|
entityId = if (lib.hasAttr "double" states) then
|
||||||
|
states.double
|
||||||
|
else
|
||||||
|
"input_boolean.double_${name}";
|
||||||
|
in {
|
||||||
|
alias = "toggle double click ${name}";
|
||||||
trigger = {
|
trigger = {
|
||||||
platform = "mqtt";
|
platform = "mqtt";
|
||||||
topic = "zigbee2mqtt/${button}";
|
topic = "zigbee2mqtt/${name}";
|
||||||
};
|
};
|
||||||
condition = {
|
condition = {
|
||||||
condition = "template";
|
condition = "template";
|
||||||
|
@ -377,16 +416,23 @@ in {
|
||||||
};
|
};
|
||||||
action = {
|
action = {
|
||||||
service = "input_boolean.toggle";
|
service = "input_boolean.toggle";
|
||||||
data.entity_id = "input_boolean.double_${button}";
|
data.entity_id = entityId;
|
||||||
};
|
};
|
||||||
}) (builtins.attrNames sensors.buttons);
|
}) sensors.buttons;
|
||||||
|
|
||||||
# hold
|
# hold
|
||||||
toggle_hold_button_input = map (button: {
|
toggle_hold_button_input = lib.mapAttrsToList (name:
|
||||||
alias = "toggle hold ${button}";
|
{ states ? { }, ... }:
|
||||||
|
let
|
||||||
|
entityId = if (lib.hasAttr "hold" states) then
|
||||||
|
states.hold
|
||||||
|
else
|
||||||
|
"input_boolean.hold_${name}";
|
||||||
|
in {
|
||||||
|
alias = "toggle hold ${name}";
|
||||||
trigger = {
|
trigger = {
|
||||||
platform = "mqtt";
|
platform = "mqtt";
|
||||||
topic = "zigbee2mqtt/${button}";
|
topic = "zigbee2mqtt/${name}";
|
||||||
};
|
};
|
||||||
condition = {
|
condition = {
|
||||||
condition = "template";
|
condition = "template";
|
||||||
|
@ -394,9 +440,9 @@ in {
|
||||||
};
|
};
|
||||||
action = {
|
action = {
|
||||||
service = "input_boolean.toggle";
|
service = "input_boolean.toggle";
|
||||||
data.entity_id = "input_boolean.hold_${button}";
|
data.entity_id = entityId;
|
||||||
};
|
};
|
||||||
}) (builtins.attrNames sensors.buttons);
|
}) sensors.buttons;
|
||||||
|
|
||||||
in lib.flatten (toggle_single_button_input ++ toggle_double_button_input
|
in lib.flatten (toggle_single_button_input ++ toggle_double_button_input
|
||||||
++ toggle_hold_button_input);
|
++ toggle_hold_button_input);
|
||||||
|
|
Loading…
Reference in a new issue