-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Template Light Platform documentation #2661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
emlove
merged 6 commits into
home-assistant:next
from
cribbstechnologies:light-template
May 24, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1afaf1
creating docs for light template platform
cribbstechnologies 7fb8bff
escaping templates
cribbstechnologies 7c9a8d6
updating docs with a more simple example
cribbstechnologies 3c71c8b
updating example text
cribbstechnologies c125f89
making descrption more standalone
cribbstechnologies 9f32bc6
updating docs to include missing field and make example name more inl…
cribbstechnologies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
--- | ||
layout: page | ||
title: "Template Light" | ||
description: "Instructions how to integrate Template lights into Home Assistant." | ||
date: 2016-05-18 20:32 | ||
sidebar: true | ||
comments: false | ||
sharing: true | ||
footer: true | ||
ha_category: Light | ||
ha_release: 0.46 | ||
ha_iot_class: "Local Push" | ||
logo: home-assistant.png | ||
--- | ||
|
||
The `template` platform creates lights that combine components and provides the ability to run scripts or invoke services for each of the on, off, and brightness commands of a light. | ||
|
||
To enable Template lights in your installation, add the following to your `configuration.yaml` file: | ||
|
||
```yaml | ||
# Example configuration.yaml entry | ||
light: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A simpler example for users getting started could be preferable and having the advanced one as an option after the configuration variables. |
||
- platform: template | ||
lights: | ||
theater_lights: | ||
friendly_name: "Theater Lights" | ||
value_template: "{% raw %}{{is_state('sensor.theater_brightness.attributes.lux > 0'}}{% endraw %}" | ||
turn_on: | ||
service: script.theater_lights_on | ||
turn_off: | ||
service: script.theater_lights_off | ||
set_level: | ||
service: script.theater_lights_level | ||
data_template: | ||
volume_level: "{% raw %}{{brightness}}{% endraw %}" | ||
level_template: "{% raw %}{{is_state('sensor.theater_brightness.attributes.lux'}}{% endraw %}" | ||
``` | ||
|
||
Configuration variables: | ||
|
||
- **lights** array (*Required*): List of your lights. | ||
- **friendly_name** (*Optional*): Name to use in the Frontend. | ||
- **value_template** (*Optional*): Defines a [template](/topics/templating/) to get the state of the light. If not provided the component defaults to optimisitc state determination. | ||
- **turn_on** (*Required*): Defines an [action](/getting-started/automation/) to run when the light is turned on. | ||
- **turn_off** (*Required*): Defines an [action](/getting-started/automation/) to run when the light is turned off. | ||
- **set_level** (*Optional*): Defines an [action](/getting-started/automation/) to run when the light is given a brightness command. | ||
- **level_template** (*Optional): Defines a [template](/topics/templating/) to get the brightness of the light. If not provided the component defaults to optimisitc brightness determination. | ||
- **entity_id** (*Optional*): Add a list of entity IDs so the switch only reacts to state changes of these entities. This will reduce the number of times the light will try to update it's state. | ||
|
||
|
||
## {% linkable_title Considerations %} | ||
|
||
If you are using the state of a platform that takes extra time to load, the template light may get an 'unknown' state during startup. This results in error messages in your log file until that platform has completed loading. If you use is_state() function in your template, you can avoid this situation. For example, you would replace {% raw %}'{{ states.switch.source.state }}'{% endraw %} with this equivalent that returns true/false and never gives an unknown result: | ||
{% raw %}'{{ is_state('switch.source', 'on') }}'{% endraw %} | ||
|
||
## {% linkable_title Examples %} | ||
|
||
In this section you will find some real life examples of how to use this light. | ||
|
||
### {% linkable_title Theater Volume Control %} | ||
|
||
This example shows a light that is actually a home theater's volume. This component gives you the flexibility to provide whatever you'd like to send as the payload to the consumer including any scale conversions you may need to make; the media_player component needs a floating point percentage value 0.0-1.0 | ||
|
||
```yaml | ||
light: | ||
- platform: template | ||
lights: | ||
theater_volume: | ||
friendly_name: 'Receiver Volume' | ||
value_template: >- | ||
{% raw %} | ||
{%- if is_state("media_player.receiver", "on") -%} | ||
{%- if states.media_player.receiver.attributes.is_volume_muted -%} | ||
off | ||
{%- else -%} | ||
on | ||
{%- endif -%} | ||
{%- else -%} | ||
off | ||
{%- endif -%} | ||
{% endraw %} | ||
turn_on: | ||
service: media_player.volume_mute | ||
data: | ||
entity_id: media_player.receiver | ||
is_volume_muted: false | ||
turn_off: | ||
service: media_player.volume_mute | ||
data: | ||
entity_id: media_player.receiver | ||
is_volume_muted: true | ||
set_level: | ||
service: media_player.volume_set | ||
data: | ||
entity_id: media_player.receiver | ||
data_template: | ||
volume_level: '{% raw %}{{((brightness / 255 * 100) | int)/100}}{% endraw %}' | ||
level_template: >- | ||
{% raw %} | ||
{%- if is_state("media_player.receiver", "on") -%} | ||
{{(255 * states.media_player.receiver.attributes.volume_level) | int}} | ||
{%- else -%} | ||
0 | ||
{%- endif -%} | ||
{% endraw %} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example doesn't seem to have anything todo with lights?