mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-19 15:26:59 +00:00
Add MQTT Automation Example (#2070)
* Update input_select.markdown I added an MQTT automation example similar to the one on the input_slider component page. * Fixed Typo Fixed "Exampleof" typo.
This commit is contained in:
parent
1e769ba9b2
commit
ee71668a07
@ -79,3 +79,49 @@ scene:
|
|||||||
input_select.who_cooks:
|
input_select.who_cooks:
|
||||||
option: Paulus
|
option: Paulus
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example of `input_select` being used in a bidirectional manner, both being set by and controlled by an MQTT action in an automation.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
{% raw %}
|
||||||
|
# Example configuration.yaml entry using 'input_select' in an action in an automation
|
||||||
|
|
||||||
|
# Define input_select
|
||||||
|
input_select:
|
||||||
|
thermostat_mode:
|
||||||
|
name: Thermostat Mode
|
||||||
|
options:
|
||||||
|
- "auto"
|
||||||
|
- "off"
|
||||||
|
- "cool"
|
||||||
|
- "heat"
|
||||||
|
icon: mdi:target
|
||||||
|
|
||||||
|
# Automation.
|
||||||
|
# This automation script runs when a value is received via MQTT on retained topic: thermostatMode
|
||||||
|
# It sets the value selector on the GUI. This selector also had its own automation when the value is changed.
|
||||||
|
- alias: Set Thermostat Mode Selector
|
||||||
|
trigger:
|
||||||
|
platform: mqtt
|
||||||
|
topic: "thermostatMode"
|
||||||
|
# entity_id: input_select.thermostat_mode
|
||||||
|
action:
|
||||||
|
service: input_select.select_option
|
||||||
|
data_template:
|
||||||
|
entity_id: input_select.thermostat_mode
|
||||||
|
option: '{{ trigger.payload }}'
|
||||||
|
|
||||||
|
# This automation script runs when the thermostat mode selector is changed.
|
||||||
|
# It publishes its value to the same MQTT topic it is also subscribed to.
|
||||||
|
- alias: Set Thermostat Mode
|
||||||
|
trigger:
|
||||||
|
platform: state
|
||||||
|
entity_id: input_select.thermostat_mode
|
||||||
|
action:
|
||||||
|
service: mqtt.publish
|
||||||
|
data_template:
|
||||||
|
topic: "thermostatMode"
|
||||||
|
retain: true
|
||||||
|
payload: '{{ states.input_select.thermostat_mode.state }}'
|
||||||
|
{% endraw %}
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user