summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/bureautomation/automation/schlechteluft.nix
blob: ea1d445157e7ff95e4c0a377ce6999cab3135f2c (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
let
  long_threshold = 30;
in
{
  services.home-assistant.config.automation =
  [
    {
      alias = "Bad Air Alarm 60 seconds";
      trigger =
      { platform = "numeric_state";
        entity_id = "sensor.air_quality";
        above = 1523;
        for.seconds = 60;
      };
      condition = {
        condition = "and";
        conditions = [
          { condition = "state";
            entity_id = "group.team";
            state = "home";
          }
          { condition = "time";
            after   = "06:00:00";
            before  = "20:00:00";
          }
        ];
      };

      action = [
        { service = "homeassistant.turn_on";
          entity_id = [
            "script.schlechteluft"
          ];
        }
      ];
    }
    {
      alias = "Bad Air Alarm ${toString long_threshold} Minutes";
      trigger =
      { platform = "numeric_state";
        entity_id = "sensor.air_quality";
        above = 1523;
        for.minutes = long_threshold;
      };
      condition = {
        condition = "and";
        conditions = [
          { condition = "state";
            entity_id = "group.team";
            state = "home";
          }
          { condition = "time";
            after   = "06:00:00";
            before  = "20:00:00";
          }
        ];
      };

      action = [
        { service = "homeassistant.turn_on";
          entity_id = [
            "script.schlechteluft"
          ];
        }
        { service = "tts.google_say";
          entity_id =  "media_player.mpd";
          data_template = {
            message = "BEEP BEEP - Die luft ist schon ${toString long_threshold} Minuten schlecht! Student Nummer {{ range(1,500) | random }}, öffne ein Fenster.";
            language = "de";
          };
        }
      ];
    }
  ];
}