Skip to content

Commit fe91174

Browse files
DiaoulLandrash
authored andcommitted
Add support for light effects in mqtt_template (home-assistant#1489)
* Add support for light effects in mqtt_template
1 parent 5ae3d4b commit fe91174

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

source/_components/light.mqtt_template.markdown

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ha_release: 0.33
1717
The `mqtt_template` light platform lets you control a MQTT-enabled light that receive commands on a command topic and optionally sends status update on a state topic.
1818
It is format-agnostic so you can use any data format you want (i.e. string, JSON), just configure it with templating.
1919

20-
This platform supports on/off, brightness, RGB colors, transitions, and short/long flashing.
20+
This platform supports on/off, brightness, RGB colors, transitions, short/long flashing and effects.
2121

2222
In an ideal scenario, the MQTT device will have a state topic to publish state changes. If these messages are published with the RETAIN flag, the MQTT light will receive an instant state update after subscription and will start with the correct state. Otherwise, the initial state of the light will be off.
2323

@@ -37,15 +37,17 @@ light:
3737
Configuration variables:
3838
3939
- **name** (*Optional*): The name of the light. Default is "MQTT Template Light."
40+
- **effect_list** (*Optional*): List of possible effects.
4041
- **command_topic** (*Required*): The MQTT topic to publish commands to change the light's state.
4142
- **state_topic** (*Optional*): The MQTT topic subscribed to receive state updates.
42-
- **command_on_template** (*Required*): The template for *on* state changes. Available variables: `state`, `brightness`, `red`, `green`, `blue`, `flash` and `transition`.
43+
- **command_on_template** (*Required*): The template for *on* state changes. Available variables: `state`, `brightness`, `red`, `green`, `blue`, `flash`, `transition` and `effect`.
4344
- **command_off_template** (*Required*): The template for *off* state changes. Available variables: `state` and `transition`.
4445
- **state_template** (*Optional*): Template to extract state from the state payload value.
4546
- **brightness_template** (*Optional*): Template to extract brightness from the state payload value.
4647
- **red_template** (*Optional*): Template to extract red color from the state payload value.
4748
- **green_template** (*Optional*): Template to extract green color from the state payload value.
4849
- **blue_template** (*Optional*): Template to extract blue color from the state payload value.
50+
- **effect_template** (*Optional*): Template to extract effect from the state payload value.
4951
- **optimistic** (*Optional*): Flag that defines if the light works in optimistic mode. Default is true if no state topic or state template is defined, else false.
5052
- **qos** (*Optional*): The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages.
5153

@@ -78,12 +80,15 @@ light:
7880
7981
### {% linkable_title JSON payload %}
8082
81-
For a JSON payload with the format `{"state": "on", "brightness": 255, "color": [255, 255, 255]}`, add the following to your `configuration.yaml` file:
83+
For a JSON payload with the format `{"state": "on", "brightness": 255, "color": [255, 255, 255], "effect": "rainbow"}`, add the following to your `configuration.yaml` file:
8284

8385
```yaml
8486
# Example configuration.yaml entry
8587
light:
8688
- platform: mqtt_template
89+
effect_list:
90+
- rainbow
91+
- colorloop
8792
command_topic: "home/rgb1/set"
8893
state_topic: "home/rgb1/status"
8994
command_on_template: >{% raw %}
@@ -94,16 +99,20 @@ light:
9499
{%- if red is defined and green is defined and blue is defined -%}
95100
, "color": [{{ red }}, {{ green }}, {{ blue }}]
96101
{%- endif -%}
102+
{%- if effect is defined -%}
103+
, "effect": "{{ effect }}"
104+
{%- endif -%}
97105
}{% endraw %}
98106
command_off_template: '{"state": "off"}'
99107
state_template: '{% raw %}{{ value_json.state }}{% endraw %}'
100108
brightness_template: '{% raw %}{{ value_json.brightness }}{% endraw %}'
101109
red_template: '{% raw %}{{ value_json.color[0] }}{% endraw %}'
102110
green_template: '{% raw %}{{ value_json.color[1] }}{% endraw %}'
103111
blue_template: '{% raw %}{{ value_json.color[2] }}{% endraw %}'
112+
effect_template: '{% raw %}{{ value_json.effect }}{% endraw %}'
104113
```
105114

106115
### {% linkable_title No brightness or color support %}
107116

108-
If you don't want brightness or color support, just omit the corresponding configuration sections.
117+
If you don't want brightness, color or effect support, just omit the corresponding configuration sections.
109118

0 commit comments

Comments
 (0)