summaryrefslogtreecommitdiffstats
path: root/krebs/2configs/shack/glados/automation/shack-startup.nix
blob: 35314923b0cdacbbf24a8bb1f8282e5b82977713 (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
# needs:
#   binary_sensor.portal_lock
#   sensor.keyholder
#   media_player.lounge
let
  glados = import ../lib;
in
[
  {
    alias = "Greet new keyholder for key exchange";
    initial_state = true;
    trigger = {
      platform = "state";
      entity_id = "sensor.keyholder";
    };
    condition = {
      condition = "template";
      value_template = "{{ trigger.from_state.state != 'No Keyholder' }}";
    };
    action = glados.say.kiosk "Danke {{trigger.to_state.state}} für das Übernehmen des Keys von {{trigger.from_state.state}}";
    # action = [];
  }

  {
    alias = "Start Music on portal lock on";
    # TODO: use "power" trigger
    trigger = {
      platform = "state";
      entity_id = "binary_sensor.portal_lock";
      to = "on";
      for.seconds = 30;
    };
    condition = {
      condition = "and";
      conditions =
      [
        { # only start if a keyholder opened the door and if the lounge mpd is currently not playing anything
          condition = "template";
          value_template = "{{ state('sensor.keyholder') != 'No Keyholder' }}";
        }
        {
          condition = "state";
          entity_id = "media_player.lounge";
          state = "idle";
        }
      ];
    };
    action =  [
        {
          service = "media_player.volume_set";
          data = {
            entity_id = "media_player.lounge";
            volume_level = 1.0;
          };
        }
        {
          service = "media_player.play_media";
          data = {
            entity_id = "media_player.lounge";
            media_content_type = "playlist";
            media_content_id = "ansage";
          };
        }
        { delay.seconds = 8; }
        {
          service = "media_player.volume_set";
          data = {
            entity_id = "media_player.lounge";
            volume_level = 0.6;
          };
        }
        {
          service = "media_player.play_media";
          data = {
            entity_id = "media_player.lounge";
            media_content_type =  "playlist";
            media_content_id = "lassulus superradio";
          };
        }
      ];
  }
]