-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfade-volume.yaml
76 lines (76 loc) · 2.37 KB
/
fade-volume.yaml
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
fade_volume:
alias: Fade the volume of a media player
mode: restart
fields:
target_player:
name: Target media player
description: Target media player of volume fade.
required: true
example: media_player.lounge_sonos
selector:
entity:
domain: media_player
target_volume:
name: Target volume
description: Volume the media play will be at the end of the fade duration.
required: true
default: 0.5
example: '0.5'
selector:
number:
max: 1
min: 0
step: 0.01
mode: slider
duration:
name: Fade duration
description: Length of time in seconds the fade should take.
required: true
default: 5
example: '5'
selector:
number:
mode: box
min: 0
max: 100000
unit_of_measurement: s
curve:
name: Fade curve algorithm
description: Shape of the fade curve to apply.
required: true
default: logarithmic
example: logarithmic
selector:
select:
options:
- logarithmic
- bezier
- linear
variables:
steps_per_second: 10
total_steps: '{{ (steps_per_second * duration) | int(0) }}'
start_volume: '{{ state_attr(target_player, ''volume_level'') | float(0) }}'
start_diff: '{{ (target_volume - start_volume) | float(0) }}'
sequence:
- repeat:
while:
- condition: template
value_template: '{{ repeat.index < total_steps }}'
- condition: template
value_template: '{{ ((state_attr(target_player, "volume_level") - target_volume)
| abs) > 0.001 }}'
sequence:
- service: media_player.volume_set
data_template:
entity_id: '{{ target_player }}'
volume_level: "{% set t = repeat.index / total_steps %} {% if curve == 'logarithmic'\
\ %}\n {{ (start_volume + (t / (1 + (1 - t))) * start_diff) | float(0)\
\ }}\n{% elif curve == 'bezier' %}\n {{ (start_volume + (t * t * (3 -\
\ 2 * t)) * start_diff) | float(0) }}\n{% else %}\n {{ (start_volume\
\ + t * start_diff) | float(0) }}\n{% endif %}\n"
- delay: '00:00:00.1'
- service: media_player.volume_set
data_template:
entity_id: '{{ target_player }}'
volume_level: '{{ target_volume }}'
icon: mdi:tune-vertical