diff --git a/configs/pepe/home-assistant.nix b/configs/pepe/home-assistant.nix index 891c6db..2894a79 100644 --- a/configs/pepe/home-assistant.nix +++ b/configs/pepe/home-assistant.nix @@ -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 diff --git a/configs/pepe/home-assistant/light-control.nix b/configs/pepe/home-assistant/light-control.nix index e9fafa9..8ffce1f 100644 --- a/configs/pepe/home-assistant/light-control.nix +++ b/configs/pepe/home-assistant/light-control.nix @@ -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"; diff --git a/configs/pepe/home-assistant/zigbee2mqtt.nix b/configs/pepe/home-assistant/zigbee2mqtt.nix index 7a34daf..723d66f 100644 --- a/configs/pepe/home-assistant/zigbee2mqtt.nix +++ b/configs/pepe/home-assistant/zigbee2mqtt.nix @@ -8,6 +8,7 @@ ./zigbee2mqtt/motion.nix ./zigbee2mqtt/service.nix ./zigbee2mqtt/temperatur.nix + ./zigbee2mqtt/windows.nix ]; services.zigbee2mqtt = { diff --git a/configs/pepe/home-assistant/zigbee2mqtt/leds.nix b/configs/pepe/home-assistant/zigbee2mqtt/leds.nix index 24a080e..1e23623 100644 --- a/configs/pepe/home-assistant/zigbee2mqtt/leds.nix +++ b/configs/pepe/home-assistant/zigbee2mqtt/leds.nix @@ -17,7 +17,7 @@ in { value = { retain = false; friendly_name = name; - #osram_set_transition = 2; # time in seconds (integer or float) + transition = 1; }; }) allDevices; diff --git a/configs/pepe/home-assistant/zigbee2mqtt/windows.nix b/configs/pepe/home-assistant/zigbee2mqtt/windows.nix new file mode 100644 index 0000000..ea31367 --- /dev/null +++ b/configs/pepe/home-assistant/zigbee2mqtt/windows.nix @@ -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; + # }; + + }; + +}