From ee71668a07adddf8a9b4d3b8582ebdf07ff03c4b Mon Sep 17 00:00:00 2001 From: scottocs11 Date: Thu, 23 Feb 2017 05:35:42 -0500 Subject: [PATCH] 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. --- source/_components/input_select.markdown | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/source/_components/input_select.markdown b/source/_components/input_select.markdown index 77734c84f75..45dbc19c0d8 100644 --- a/source/_components/input_select.markdown +++ b/source/_components/input_select.markdown @@ -79,3 +79,49 @@ scene: input_select.who_cooks: 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 %} +```