Skip to content

Commit 257dea7

Browse files
bachyaballoob
authored andcommitted
Documentation additions (home-assistant#3654)
1 parent 0582ebc commit 257dea7

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed

source/_components/cover.template.markdown

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,69 @@ automation:
251251
position: 25
252252
```
253253
{% endraw %}
254+
255+
### {% linkable_title Change The Icon %}
256+
257+
This example shows how to change the icon based on the cover state.
258+
259+
{% raw %}
260+
```yaml
261+
cover:
262+
- platform: template
263+
covers:
264+
cover_group:
265+
friendly_name: "Cover Group"
266+
open_cover:
267+
service: script.cover_group
268+
data:
269+
modus: 'open'
270+
close_cover:
271+
service: script.cover_group
272+
data:
273+
modus: 'close'
274+
stop_cover:
275+
service: script.cover_group
276+
data:
277+
modus: 'stop'
278+
value_template: "{{is_state('sensor.cover_group', 'open')}}"
279+
icon_template: >-
280+
{% if is_state('sensor.cover_group', 'open') %}
281+
mdi:window-open
282+
{% else %}
283+
mdi:window-closed
284+
{% endif %}
285+
```
286+
{% endraw %}
287+
288+
### {% linkable_title Change The Entity Picture %}
289+
290+
This example shows how to change the entity picture based on the cover state.
291+
292+
{% raw %}
293+
```yaml
294+
cover:
295+
- platform: template
296+
covers:
297+
cover_group:
298+
friendly_name: "Cover Group"
299+
open_cover:
300+
service: script.cover_group
301+
data:
302+
modus: 'open'
303+
close_cover:
304+
service: script.cover_group
305+
data:
306+
modus: 'close'
307+
stop_cover:
308+
service: script.cover_group
309+
data:
310+
modus: 'stop'
311+
value_template: "{{is_state('sensor.cover_group', 'open')}}"
312+
icon_template: >-
313+
{% if is_state('sensor.cover_group', 'open') %}
314+
/local/cover-open.png
315+
{% else %}
316+
/local/cover-closed.png
317+
{% endif %}
318+
```
319+
{% endraw %}

source/_components/light.template.markdown

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,91 @@ light:
143143
{% endif %}
144144
```
145145
{% endraw %}
146+
147+
### {% linkable_title Change The Icon %}
148+
149+
This example shows how to change the icon based on the light state.
150+
151+
{% raw %}
152+
```yaml
153+
light:
154+
- platform: template
155+
lights:
156+
theater_volume:
157+
friendly_name: "Receiver Volume"
158+
value_template: >-
159+
{% if is_state('media_player.receiver', 'on') %}
160+
{% if states.media_player.receiver.attributes.is_volume_muted %}
161+
off
162+
{% else %}
163+
on
164+
{% endif %}
165+
{% else %}
166+
off
167+
{% endif %}
168+
icon_template: >-
169+
{% if is_state('media_player.receiver', 'on') %}
170+
{% if states.media_player.receiver.attributes.is_volume_muted %}
171+
mdi:lightbulb-off
172+
{% else %}
173+
mdi:lightbulb-on
174+
{% endif %}
175+
{% else %}
176+
mdi:lightbulb-off
177+
{% endif %}
178+
turn_on:
179+
service: media_player.volume_mute
180+
data:
181+
entity_id: media_player.receiver
182+
is_volume_muted: false
183+
turn_off:
184+
service: media_player.volume_mute
185+
data:
186+
entity_id: media_player.receiver
187+
is_volume_muted: true
188+
```
189+
{% endraw %}
190+
191+
### {% linkable_title Change The Entity Picture %}
192+
193+
This example shows how to change the entity picture based on the light state.
194+
195+
{% raw %}
196+
```yaml
197+
light:
198+
- platform: template
199+
lights:
200+
theater_volume:
201+
friendly_name: "Receiver Volume"
202+
value_template: >-
203+
{% if is_state('media_player.receiver', 'on') %}
204+
{% if states.media_player.receiver.attributes.is_volume_muted %}
205+
off
206+
{% else %}
207+
on
208+
{% endif %}
209+
{% else %}
210+
off
211+
{% endif %}
212+
icon_template: >-
213+
{% if is_state('media_player.receiver', 'on') %}
214+
{% if states.media_player.receiver.attributes.is_volume_muted %}
215+
/local/lightbulb-off.png
216+
{% else %}
217+
/local/lightbulb-on.png
218+
{% endif %}
219+
{% else %}
220+
/local/lightbulb-off.png
221+
{% endif %}
222+
turn_on:
223+
service: media_player.volume_mute
224+
data:
225+
entity_id: media_player.receiver
226+
is_volume_muted: false
227+
turn_off:
228+
service: media_player.volume_mute
229+
data:
230+
entity_id: media_player.receiver
231+
is_volume_muted: true
232+
```
233+
{% endraw %}

source/_components/sensor.template.markdown

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ sensor:
6161
description: Defines a template for the icon of the sensor.
6262
required: false
6363
type: template
64+
icon_template:
65+
description: Defines a template for the entity picture of the sensor.
66+
required: false
67+
type: template
6468
{% endconfiguration %}
6569
6670
## {% linkable_title Considerations %}
@@ -215,3 +219,29 @@ sensor:
215219
{% endif %}
216220
```
217221
{% endraw %}
222+
223+
### {% linkable_title Change The Entity Picture %}
224+
225+
This example shows how to change the entity picture based on the day/night cycle.
226+
227+
{% raw %}
228+
```yaml
229+
sensor:
230+
- platform: template
231+
sensors:
232+
day_night:
233+
friendly_name: "Day/Night"
234+
value_template: >-
235+
{% if is_state('sun.sun', 'above_horizon') %}
236+
Day
237+
{% else %}
238+
Night
239+
{% endif %}
240+
entity_picture_template: >-
241+
{% if is_state('sun.sun', 'above_horizon') %}
242+
/local/daytime.png
243+
{% else %}
244+
/local/nighttime.png
245+
{% endif %}
246+
```
247+
{% endraw %}

source/_components/switch.template.markdown

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,31 @@ switch:
186186
{% endif %}
187187
```
188188
{% endraw %}
189+
190+
### {% linkable_title Change The Entity Picture %}
191+
192+
This example shows how to change the entity picture based on the day/night cycle.
193+
194+
{% raw %}
195+
```yaml
196+
switch:
197+
- platform: template
198+
switches:
199+
garage:
200+
value_template: "{{ is_state('cover.garage_door', 'on') }}"
201+
turn_on:
202+
service: cover.open_cover
203+
data:
204+
entity_id: cover.garage_door
205+
turn_off:
206+
service: cover.close_cover
207+
data:
208+
entity_id: cover.garage_door
209+
entity_picture_template: >-
210+
{% if is_state('cover.garage_door', 'open') %}
211+
/local/garage-open.png
212+
{% else %}
213+
/local/garage-closed.png
214+
{% endif %}
215+
```
216+
{% endraw %}

0 commit comments

Comments
 (0)