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
|
||||||
lib.mapAttrsToList (name: values: { name = name; } // values)
|
createGroupEntities = { sensors, entityNameing }:
|
||||||
sensors.motion;
|
let
|
||||||
motionAllRooms' =
|
flatSensors =
|
||||||
lib.groupBy ({ room ? "unknown", ... }: room) flatMotionSensors;
|
lib.mapAttrsToList (name: values: { name = name; } // values)
|
||||||
motionAllRooms = lib.mapAttrs
|
sensors;
|
||||||
(_: devices: map ({ name, ... }: "binary_sensor.${name}") devices)
|
allRooms' =
|
||||||
motionAllRooms';
|
lib.groupBy ({ room ? "unknown", ... }: room) flatSensors;
|
||||||
|
allRooms =
|
||||||
|
lib.mapAttrs (_: devices: map entityNameing devices) allRooms';
|
||||||
|
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,55 +373,76 @@ 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 ? { }, ... }:
|
||||||
trigger = {
|
let
|
||||||
platform = "mqtt";
|
entityId = if (lib.hasAttr "single" states) then
|
||||||
topic = "zigbee2mqtt/${button}";
|
states.single
|
||||||
};
|
else
|
||||||
condition = {
|
"input_boolean.single_${name}";
|
||||||
condition = "template";
|
in {
|
||||||
value_template = ''{{ "single" == trigger.payload_json.click}}'';
|
alias = "toggle single click ${name}";
|
||||||
};
|
trigger = {
|
||||||
action = {
|
platform = "mqtt";
|
||||||
service = "input_boolean.toggle";
|
topic = "zigbee2mqtt/${name}";
|
||||||
data.entity_id = "input_boolean.single_${button}";
|
};
|
||||||
};
|
condition = {
|
||||||
}) (builtins.attrNames sensors.buttons);
|
condition = "template";
|
||||||
|
value_template = ''{{ "single" == trigger.payload_json.click}}'';
|
||||||
|
};
|
||||||
|
action = {
|
||||||
|
service = "input_boolean.toggle";
|
||||||
|
data.entity_id = entityId;
|
||||||
|
};
|
||||||
|
}) sensors.buttons;
|
||||||
|
|
||||||
# double click
|
# double click
|
||||||
toggle_double_button_input = map (button: {
|
toggle_double_button_input = lib.mapAttrsToList (name:
|
||||||
alias = "toggle hold ${button}";
|
{ states ? { }, ... }:
|
||||||
trigger = {
|
let
|
||||||
platform = "mqtt";
|
entityId = if (lib.hasAttr "double" states) then
|
||||||
topic = "zigbee2mqtt/${button}";
|
states.double
|
||||||
};
|
else
|
||||||
condition = {
|
"input_boolean.double_${name}";
|
||||||
condition = "template";
|
in {
|
||||||
value_template = ''{{ "double" == trigger.payload_json.click}}'';
|
alias = "toggle double click ${name}";
|
||||||
};
|
trigger = {
|
||||||
action = {
|
platform = "mqtt";
|
||||||
service = "input_boolean.toggle";
|
topic = "zigbee2mqtt/${name}";
|
||||||
data.entity_id = "input_boolean.double_${button}";
|
};
|
||||||
};
|
condition = {
|
||||||
}) (builtins.attrNames sensors.buttons);
|
condition = "template";
|
||||||
|
value_template = ''{{ "double" == trigger.payload_json.click}}'';
|
||||||
|
};
|
||||||
|
action = {
|
||||||
|
service = "input_boolean.toggle";
|
||||||
|
data.entity_id = entityId;
|
||||||
|
};
|
||||||
|
}) sensors.buttons;
|
||||||
|
|
||||||
# hold
|
# hold
|
||||||
toggle_hold_button_input = map (button: {
|
toggle_hold_button_input = lib.mapAttrsToList (name:
|
||||||
alias = "toggle hold ${button}";
|
{ states ? { }, ... }:
|
||||||
trigger = {
|
let
|
||||||
platform = "mqtt";
|
entityId = if (lib.hasAttr "hold" states) then
|
||||||
topic = "zigbee2mqtt/${button}";
|
states.hold
|
||||||
};
|
else
|
||||||
condition = {
|
"input_boolean.hold_${name}";
|
||||||
condition = "template";
|
in {
|
||||||
value_template = ''{{ "hold" == trigger.payload_json.action }}'';
|
alias = "toggle hold ${name}";
|
||||||
};
|
trigger = {
|
||||||
action = {
|
platform = "mqtt";
|
||||||
service = "input_boolean.toggle";
|
topic = "zigbee2mqtt/${name}";
|
||||||
data.entity_id = "input_boolean.hold_${button}";
|
};
|
||||||
};
|
condition = {
|
||||||
}) (builtins.attrNames sensors.buttons);
|
condition = "template";
|
||||||
|
value_template = ''{{ "hold" == trigger.payload_json.action}}'';
|
||||||
|
};
|
||||||
|
action = {
|
||||||
|
service = "input_boolean.toggle";
|
||||||
|
data.entity_id = entityId;
|
||||||
|
};
|
||||||
|
}) 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