summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/ham/multi/the_playlist.nix
blob: 0d714ea44e23456ef60d36edf3ce45e13da7129a (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
# Inputs:
#  binary_sensor.playlist_button_good
#  binary_sensor.playlist_button_bad

# outputs
#  rest_command
#  automation
#  sensor
{
  services.home-assistant.config =
  {
    rest_command = {
      good_song = {
        url = "http://prism.r:8001/good";
        method = "POST";
      };
      bad_song = {
        url = "http://prism.r:8001/skip";
        method = "POST";
      };
    };
    automation = [
      {
        alias = "playlist song publish";
        trigger = {
          #platform = "event";
          #event_data.entity_id = "sensor.the_playlist_song";
          platform = "state";
          entity_id = "sensor.the_playlist_song";
        };
        action = {
          service = "mqtt.publish";
          data = {
            topic = "/ham/the_playlist/song";
            payload_template = "{{ states.sensor.the_playlist_song.state }}";
          };
        };
      }
      {
        alias = "playlist upvote on button";
        trigger = {
          platform = "state";
          entity_id = "binary_sensor.playlist_button_good";
          from = "off";
          to = "on";
        };
        action.service = "rest_command.good_song";
      }
      {
        alias = "playlist downvote on button";
        trigger = {
          platform = "state";
          entity_id = "binary_sensor.playlist_button_bad";
          from = "off";
          to = "on";
        };
        action.service = "rest_command.bad_song";
      }
    ];
    sensor =  [
      { platform = "rest";
        name = "pl";
        resource = "http://prism.r:8001/current";
        scan_interval = 30;
        value_template = "1";
        json_attributes = [ "name" "filename" "youtube" ];
      }
      { platform = "template";
        sensors = {
          the_playlist_song = {
            friendly_name = "Current Song";
            value_template = ''{{ states.sensor.pl.attributes['name'] }}'';
          };
          the_playlist_url = {
            friendly_name = "Song Youtube URL";
            value_template = ''{{ states.sensor.pl.attributes['youtube'] }}'';
          };
          the_playlist_filename = {
            friendly_name = "Song Filename";
            value_template = ''{{ states.sensor.pl.attributes['filename'] }}'';
          };
        };
      }
    ];
  };
}