summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/home/ham/automation/fenster_auf.nix
blob: 871f248b9369cbc7b433f9b181cdb57fbc29ed56 (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
{ lib, ... }:
#uses:
# notify.signal
# binary_sensor.badezimmer_fenster_contact
# binary_sensor.dusche_fenster_contact
let
  min = 20;
  fenster_offen = name: entity:
    { alias = "${name} seit ${toString min} Minuten offen";
      trigger = [
          {
            platform = "state";
            entity_id = entity;
            to = "on";
            for.minutes = min;
          }
      ];
      action =
      [
        {
          service = "notify.signal_home";
          data = {
            message= "${name} seit ${toString min} Minuten offen\nBitte einmal checken ob das ok ist :)";
          };
        }
        {
          service = "input_boolean.turn_on";
          target.entity_id = "input_boolean.${lib.toLower name}_lang_offen";
        }
      ];
    };
  fenster_geschlossen_lang = name: entity:
    { alias = "${name} wieder geschlossen";
      trigger = [
          {
            platform = "state";
            entity_id = entity;
            to = "off";
          }
        ];
      condition = [
        { condition = "state";
          entity_id = "input_boolean.${lib.toLower name}_lang_offen";
          state = "on";
        }
      ];
      action =
      [
        {
          service = "notify.signal_home";
          data = {
            message= "${name} ist wieder geschlossen, Danke!";
          };
        }
        {
          service = "input_boolean.turn_off";
          target.entity_id = "input_boolean.${lib.toLower name}_lang_offen";
        }
      ];
    };
in {
  services.home-assistant.config = {
    input_boolean = {
      badezimmerfinester_lang_offen.name = "Badezimmer lange offen";
      duschfenster_lang_offen.name = "Duschfenster lange offen";
    };
    automation = [
      (fenster_geschlossen_lang "Badezimmerfenster" "binary_sensor.badezimmer_fenster_contact")
      (fenster_geschlossen_lang "Duschfenster" "binary_sensor.badezimmer_fenster_contact")
      (fenster_offen "Badezimmerfenster" "binary_sensor.badezimmer_fenster_contact")
      (fenster_offen "Duschfenster" "binary_sensor.dusche_fenster_contact")
    ];
  };
}