summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/home/ham/automation/flurlicht.nix
blob: aa62ab9e460b30ae3fde2fbf32c2f8a1148ff18b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let
  nachtlicht = [ "light.flur_statuslight" "light.wohnzimmer_status_led" ];

  # flurlicht an
  lightcond = name: conditions: rgb_color: brightness:
  {
    inherit conditions;
    sequence = {
      service = "light.turn_on";
      target.entity_id = nachtlicht;
      data = {
        inherit rgb_color brightness;
      };
    };
  };
in
{
  services.home-assistant.config.automation =
  [
    { alias = "Nachtlicht trigger";
      trigger = [
        { platform = "sun"; event = "sunset"; }
        { platform = "sun"; event = "sunrise"; }
        { platform = "state"; entity_id = [
            "calendar.kehrwoche_kehrwoche"
            "binary_sensor.badezimmer_fenster_contact"
            "binary_sensor.dusche_fenster_contact"
          ];
        }
      ];
      action =
      [
        { choose = [
              (lightcond "Badezimmer Fenster Auf"
                { condition = "state"; entity_id = "binary_sensor.badezimmer_fenster_contact"; state =  "on"; }
                [ 64 207 255 ] 255 # helblau
              )
              (lightcond "Duschenster auf"
                { condition = "state"; entity_id = "binary_sensor.dusche_fenster_contact"; state =  "on"; }
                [ 64 207 255 ] 255 # helblau
              )
              (lightcond "Nachtlicht"
                { condition = "state"; entity_id = "sun.sun"; state =  "below_horizon"; }
                [ 255 190 0 ] 90 # red
              )
              (lightcond "Kehrwoche"
                { condition = "state"; entity_id = "calendar.kehrwoche_kehrwoche"; state =  "on"; }
                [ 204 0 255 ] 128 # pink
              )
            ];
          default = {
            service = "light.turn_off";
            entity_id = nachtlicht;
          };
        }
      ];
    }
  ];
}