blob: bd36f02cde3aad34cf34f7ede4f808621dd3ce1a (
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
{ lib, ... }:
let
remote = "sensor.schlafzimmer_music_remote_action";
hlib = import ../lib;
step = 0.02;
#room = "bedroom";
room = "office";
player = "media_player.${room}";
say = hlib.say."${room}";
remote_action = key: actions: {
conditions = ''{{ trigger.entity_id == 'binary_sensor.matrix_button_${toString key}' }}'';
sequence = actions;
};
all_buttons = map (key: "binary_sensor.matrix_button_${toString key}") [
0 1 2 3 4 5 6 7 8 9
"b9" "b10" "b11" "b12" "b13" "b14"
];
in
{
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";
};
};
services.home-assistant.config.automation =
[
{ alias = "Arbeitszimmer Matrix music action";
trigger = [
{
platform = "state";
entity_id = all_buttons;
}
];
action =
[
{ choose = [
(remote_action "9" {
service = "media_player.media_play";
target.entity_id = player;
})
(remote_action "7"
{
service = "media_player.media_mute";
target.entity_id = player;
data.is_volume_muted = ''{{ not state_attr('${player}' , 'is_volume_muted') }}'';
}
)
(remote_action "2"
{
service = "media_player.media_stop";
target.entity_id = player;
}
)
(remote_action "b9"
((say "Guter Song {{ states.sensor.the_playlist_song.state }}") ++ [
{ service = "rest_command.good_song"; }
]))
(remote_action "b10"
((say "Schlechter Song {{ states.sensor.the_playlist_song.state }}") ++ [
{ service = "rest_command.bad_song"; }
]))
(remote_action "3"
((say "Starte Lassulus Super Radio") ++ [
{ service = "media_player.play_media";
data = {
media_content_id = "http://radio.lassul.us:8000/radio.mp3";
media_content_type = "music";
};
target.entity_id = player;
}
]))
(remote_action "1"
((say "Starte Groovesalad") ++ [
{ service = "media_player.play_media";
data = {
media_content_id = "http://ice2.somafm.com/groovesalad-128.mp3";
media_content_type = "music";
};
target.entity_id = player;
}
]))
(remote_action "8" {
service = "media_player.volume_set";
target.entity_id = player;
data.volume_level = ''{{ state_attr("${player}","volume_level") + (${toString step}|float) }}'';
})
(remote_action "5"{
service = "media_player.volume_set";
target.entity_id = player;
data.volume_level = ''{{ state_attr("${player}","volume_level") - (${toString step}|float) }}'';
})
];
#default = { };
}
];
}
];
}
|