SHOW:
|
|
- or go back to the newest paste.
1 | alias: TTS wznowienie | |
2 | description: 'Obsługuje: Nabu Casa, Google Cloud, Google Translate. Wznawianie serwisu Spotify przy użyciu spotcast.' | |
3 | trigger: | |
4 | #Nabu Casa | |
5 | - platform: event | |
6 | event_type: call_service | |
7 | event_data: | |
8 | service: cloud_say | |
9 | #Google Cloud | |
10 | - platform: event | |
11 | event_type: call_service | |
12 | event_data: | |
13 | service: google_cloud_say | |
14 | #Google Translate | |
15 | - platform: event | |
16 | event_type: call_service | |
17 | event_data: | |
18 | service: google_translate_say | |
19 | action: | |
20 | #jeśli głośnik gra, to poczekaj aż TTS mu przerwie | |
21 | - choose: | |
22 | - conditions: | |
23 | - condition: template | |
24 | value_template: '{{ media_player_resume }}' | |
25 | sequence: | |
26 | - wait_template: '{{ not is_state(media_player_id, "playing") }}' | |
27 | default: [] | |
28 | #ustaw głośność | |
29 | - service: media_player.volume_set | |
30 | target: | |
31 | entity_id: '{{ media_player_id }}' | |
32 | data: | |
33 | volume_level: '{{ tts_volume_level }}' | |
34 | #poczekaj aż zacznie gadać | |
35 | - delay: 2 | |
36 | #poczekaj aż skończy gadać | |
37 | - wait_template: '{{ not is_state(media_player_id, "playing") }}' | |
38 | #przywróć poprzednią głośność (jeśli poprawnie odczytana) | |
39 | - choose: | |
40 | - conditions: | |
41 | - condition: template | |
42 | value_template: '{{ media_player_volume_level != None }}' | |
43 | sequence: | |
44 | - service: media_player.volume_set | |
45 | target: | |
46 | entity_id: '{{ media_player_id }}' | |
47 | data: | |
48 | volume_level: '{{ media_player_volume_level }}' | |
49 | default: [] | |
50 | #wznowienie poprzedniego utworu jeśli wcześniej głośnik grał, w przeciwnym razie wyłącz głośnik | |
51 | - choose: | |
52 | - conditions: | |
53 | - condition: template | |
54 | value_template: '{{ media_player_resume }}' | |
55 | sequence: | |
56 | - choose: | |
57 | - conditions: | |
58 | - condition: template | |
59 | value_template: '{{ media_player_app_name == "Spotify" }}' | |
60 | sequence: | |
61 | - service: spotcast.start | |
62 | data: | |
63 | entity_id: '{{ media_player_id }}' | |
64 | force_playback: true | |
65 | default: | |
66 | - service: media_player.play_media | |
67 | target: | |
68 | entity_id: '{{ media_player_id }}' | |
69 | data: | |
70 | media_content_type: '{{ media_player_content_type }}' | |
71 | media_content_id: '{{ media_player_content_id }}' | |
72 | default: | |
73 | - service: media_player.turn_off | |
74 | target: | |
75 | entity_id: '{{ media_player_id }}' | |
76 | mode: single | |
77 | #Zmienne ze stanem player'a, zamim TTS zacznie gadać. Wypełniane są danymi przed wykonaniem bloku 'action' | |
78 | variables: | |
79 | media_player_id: '{{ trigger.event.data.service_data.entity_id }}' | |
80 | media_player_resume: '{{ is_state(media_player_id, "playing") }}' | |
81 | media_player_content_id: '{{ state_attr(media_player_id, "media_content_id") }}' | |
82 | media_player_volume_level: '{{ state_attr(media_player_id, "volume_level") }}' | |
83 | media_player_content_type: | | |
84 | {% set c_type = state_attr(media_player_id, "media_content_type") %} | |
85 | {% if c_type == None %} music {% else %} {{ c_type }} {% endif %} | |
86 | media_player_app_name: '{{ state_attr(media_player_id, "app_name") }}' | |
87 | #między 6:00 a 20:00 głośność 0.5, wieczorkiem 0.3 | |
88 | tts_volume_level: | | |
89 | {% set h = now().hour %} | |
90 | {% if h >= 6 and h < 20 %} 0.5 {% else %} 0.3 {% endif %} | |
91 | ||
92 | ########################################################################################################### | |
93 | #aby uzależnić głośność od konkretnego głośnika należy zmodyfikować zmienną tts_volume_level np.: | |
94 | tts_volume_level: | | |
95 | {% set h = now().hour %} | |
96 | {% if h >= 6 and h < 20 %} | |
97 | {% if media_player_id == "media_player.jbl" %} | |
98 | 0.8 | |
99 | {% elif media_player_id == "media_player.nest" %} | |
100 | 0.7 | |
101 | {% else %} | |
102 | 0.5 | |
103 | {% endif %} | |
104 | {% else %} 0.3 {% endif %} |