summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/bureautomation/automation/bureau-shutdown.nix
blob: f4c10adc8a02ae58d4b90f5773c9871a02b73335 (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
76
77
78
79
80
81
82
83
84
85
86
87
{
  services.home-assistant.config.automation =
  [
    { alias = "Turn on Fernseher on group home";
      trigger = {
        platform = "state";
        entity_id = "group.team";
        from = "not_home";
        to = "home";
        for.seconds = 30;
      };
      action = [
        {
          service = "homeassistant.turn_on";
          entity_id =  [
            "switch.fernseher"
            "switch.feuer"
          ];
        }
        {
          service = "media_player.kodi_call_method";
          data = {
            entity_id = "media_player.kodi";
            method = "Player.Open";
            item.partymode = "music";
          };
        }
        {
          service = "notify.telegrambot";
          data = {
            title = "Bureau Startup";
            message = "Das Büro wurde eröffnet";
          };
        }
      ];
    }
    { alias = "Turn off Fernseher after last in group left";
      trigger = [
        { # trigger when movement was detected at the time
          platform = "state";
          entity_id = "group.team";
          from = "home";
          to = "not_home";
        }
        { # trigger at 18:00 no matter what
          # to avoid 'everybody left before 18:00:00'
          platform = "time";
          at = "18:00:00";
        }
      ];
      action = [
        {
          service = "homeassistant.turn_off";
          entity_id =  [
            "switch.fernseher"
            "switch.feuer"
            "light.status_felix"
            "light.status_daniel"
          ];
        }
        {
          service = "notify.telegrambot";
          data_template = {
            title = "Bureau Shutdown";
            message = "All devices are turned off due to {{ trigger.platform }}";
          };
        }
      ];
      condition =
      { condition = "and";
        conditions = [
          {
            condition = "time";
            before = "06:30:00"; #only turn off between 6:30 and 18:00
            after  = "18:00:00";
            # weekday = [ "mon" "tue" "wed" "thu" "fri" ];
          }
          { # if anybody is still there
            condition = "state";
            entity_id = "group.team";
            state = "not_home";
          }
        ];
      };
    }
  ];
}