hass: add window role

This commit is contained in:
Ingolf Wagner 2020-10-28 23:56:10 +01:00
parent 8de6f4b686
commit 19d912d713
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
5 changed files with 175 additions and 7 deletions

View file

@ -180,6 +180,62 @@ in {
};
}
# window roles
{
alias = "windows down in the evening";
trigger = [{
platform = "sun";
event = "sunset";
offset = "+00:10:00"; # 10 min after sunset
}];
action = [
{
service = "mqtt.publish";
data_template = {
topic = "zigbee2mqtt/fyrtur1/set";
payload_template = ''{"position":"15"}'';
};
}
{
service = "mqtt.publish";
data_template = {
topic = "zigbee2mqtt/fyrtur2/set";
payload_template = ''{"position":"15"}'';
};
}
];
}
{
alias = "windows up in the morning";
trigger = [{
platform = "sun";
event = "sunrise";
offset = "-00:3:00"; # 3 min before sunrise
}];
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/fyrtur2/set";
payload_template = ''{"position":"90"}'';
};
}];
}
];
group = let

View file

@ -53,6 +53,10 @@
topic = "zigbee2mqtt/motion_sensor_7";
room = "sleeping_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_5";
room = "kitchen";
})
(door {
topic = "zigbee2mqtt/door_sensor_1";
@ -101,8 +105,9 @@
rooms = rooms;
delay = delay;
command = {
command = ''
{"state":"{{state}}","brightness":{{brightness}},"color":{"hex":"#FFFFFF}}'';
# Configure it once to the color you like
# {"state":"{{state}}","brightness":{{brightness}},"color":{"hex":"#FFFFFF}}
command = ''{"state":"{{state}}","brightness":{{brightness}}}'';
topic = "${topic}/set";
on = "ON";
off = "OFF";
@ -126,10 +131,10 @@
topic = "zigbee2mqtt/light_7";
rooms = [ "sleeping_room" ];
})
#(led {
# topic = "zigbee2mqtt/led_2";
# rooms = [ "sleeping_room" ];
#})
(led {
topic = "zigbee2mqtt/led_2";
rooms = [ "kitchen" ];
})
#(sonoff {
# id = "PAL01";

View file

@ -8,6 +8,7 @@
./zigbee2mqtt/motion.nix
./zigbee2mqtt/service.nix
./zigbee2mqtt/temperatur.nix
./zigbee2mqtt/windows.nix
];
services.zigbee2mqtt = {

View file

@ -17,7 +17,7 @@ in {
value = {
retain = false;
friendly_name = name;
#osram_set_transition = 2; # time in seconds (integer or float)
transition = 1;
};
}) allDevices;

View file

@ -0,0 +1,106 @@
{ 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;
# };
};
}