Home Assistant (HA) is an open source home automation solution that puts local control and privacy first.
Tasmota communicates with Home Assistant using MQTT. Before going any further, make sure MQTT is properly set up in Home Assistant and in Tasmota.
First, test if the two can communicate.
In Home Assistant web UI go to Developer Tools - MQTT. Subscribe to tele/topic%/STATE
and click START LISTENING. You should see a JSON response from your device.
To test control of a relay or light, as Publish a packet topic enter cmnd/%topic%/POWER
with payload toggle
. When you click PUBLISH your device should switch state and a JSON response will be visible in Listen to a topic window.
Home Assistant has two avenues of adding Tasmota devices:
- Using MQTT discovery
- Adding by editing configuration.yaml
!!! note "After every change to the configuration file you'll need to restart Home Assistant to make it aware of the changes."
If you don't want to use MQTT discovery, skip to Manual Configuration
Home Assistant has a feature called MQTT discovery. With MQTT discovery no user interaction or configuration file editing is needed to add new devices in Home Assistant.
!!! note "Automatic discovery is currently supported for:"
=== "Relays" Announced to Home Assistant as MQTT Switch.
To make a relay discovered as "light" in Home Assistant use command [`SetOption30 1`](Commands.md#setoption30)
_Alternatively you can configure it manually using [Light Switch](https://www.home-assistant.io/components/light.switch/) integration._
=== "Lights" Announced to Home Assistant as MQTT Light.
=== "Dimmers" Announced to Home Assistant as MQTT Light with a single channel used for dimming.
=== "Buttons" Announced to Home Assistant as Automation Trigger.
To have buttons discovered `ButtonTopic` must be set to `1` or to a custom name and it will automatically start to listen and publish using `/stat/%topic%/BUTTON<x>` topic.
When using `ButtonTopic 1` the only possible trigger will be `HOLD` (SetOption1 or SetOption11 must be enabled).
When using `ButtonTopic` with a custom name all the possible combination enabled by SetOption1, SetOption11 and Setoption13 will be possible.
`SwitchMode` default for buttons and switches is `Switchmode 0` (TOGGLE). To change the behavior, [`SwitchMode`](Commands.md#switchmode) must be changed (the Button must be configured as Switch to have effect). For example setting up a switch to `SwitchMode 1` (follow) will create a switch with ON and OFF payloads.
**When a Button is set to a different topic than `0` is not possible to use `Button#State` as a trigger for rules.**
=== "Switches" Announced to Home Assistant as MQTT Binary Sensor and/or as a Automation Trigger.
To have switches discovered `SwitchTopic` must be set to a custom name and it will automatically start to listen and publish using `/stat/%topic%/SWITCH<x>` topic.
Depending by the `SwitchMode`used, a switch can be a Trigger (`TOGGLE`or `HOLD`), a Binary Sensor (`ON`/`OFF`) or both at the same time.
Example:
When using with `SwitchMode 0` Tasmota will create just one Trigger for `TOGGLE`.
When using with `SwitchMode 1` Tasmota will create a `Binary Sensor` with `ON` and `OFF` Payloads.
When using with `Switchmode 5` Tasmota will create a `Binary Sensor` with `ON` and `OFF` Payloads and a Trigger for `TOGGLE`
All switchmodes are supported with the exception of SwitchMode11 and SwitchMode12 able to generate just a `TOGGLE` trigger.
**When a Switch is set to a different topic than `0` is not possible to use `Switch#State` as a trigger for rules.**
Types of devices not listed above (fans, covers, etc) require manual configuration
For a Tasmota device to be automatically discovered by Home Assistant you need to enable MQTT discovery with command:
SetOption19 1
!!! failure "Discovery is not built in to tasmota lite. Use the full version (tasmota.bin) for discovery."
After the automatic discovery feature is enabled a retained MQTT message starting with topic "homeassistant/" is sent to the broker. That message contains your device configuration which will be picked up and used by Home Assistant to automatically add your device.
Enabling discovery will automatically change some SetOptions to suit the new configuration:
SetOption4
to 0
Return MQTT response always as RESULT
and not as %COMMAND% topic
SetOption17
to 1
Show Color as a comma-separated decimal string instead of hexadecimal
SetOption59
to 1
Send tele/%topic%/STATE
in addition to stat/%topic%/RESULT
for commands State
, Power
and any command causing a light to be turned on.
!!! note "For every change you made on your device configuration you will need a reboot or use SetOption19 1
again to see the changes under Home Assistant."
!!! warning Please be advised that not all sensors can be correctly rendered under Home Assistant. In those cases a fallback function will be used to create a generic sensor.
To disable MQTT discovery and remove the retained message, execute SetOption19 0
.
The "homeassistant/" topic is removed from Home Assistant and MQTT broker.
All automatically discovered entities will show up under:
Configuration -> Integrations -> Configured -> MQTT
The entities are grouped by hardware, example for a Sonoff Basic:
By clicking on one of the entities, and then on the cog wheel, name in Home Assistant and entity_id
can be customized:
For every device discovered with SetOption19
an informative sensor will be created automatically:
Home Assistant (Hass) is an open-source home automation platform running on Python 3.
The advantage of manually configuring a device is that you maintain control of all aspects of the configuration.
Home Assistant configuration is done by editing the configuration.yaml
file.
!!! warning "All the configurations are just examples."
You need to be familiar with Home Assistant's configuration structure and procedures.
Straight copy paste of the given examples into configuration.yaml will not work for you.
If you are using a localized (non-english) version be sure to check the correct spelling and cases for values:
- 'payload_available'
- 'payload_not_available'
- 'payload_on'
- 'payload_off'
!!! tip
If you want the power states to be persistent in Tasmota and Home Assistant set PowerRetain 1
instead of using retain: true
in Home Assistant
Add in Home Assistant using the MQTT Switch integration.
Required Commands
SetOption59 1
- enables sending of tele/%topic%/STATE on POWER and light related commands
!!! example "Single Switch"
switch:
- platform: mqtt
name: "Tasmota Switch"
state_topic: "stat/tasmota/RESULT"
value_template: "{{ value_json.POWER }}"
command_topic: "cmnd/tasmota/POWER"
payload_on: "ON"
payload_off: "OFF"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! example "Multiple Switches" When a device has more than one relay you need to create a new switch for each relay. For each relay use corresponding POWER<x> (POWER1, POWER2, etc) or if SetOption26 is enabled)
switch:
- platform: mqtt
name: "Tasmota Switch 1"
state_topic: "stat/tasmota/RESULT"
value_template: "{{ value_json.POWER1 }}"
command_topic: "cmnd/tasmota/POWER1"
payload_on: "ON"
payload_off: "OFF"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
- platform: mqtt
name: "Tasmota Switch 2"
state_topic: "stat/tasmota/RESULT"
value_template: "{{ value_json.POWER2 }}"
command_topic: "cmnd/tasmota/POWER2"
payload_on: "ON"
payload_off: "OFF"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
- platform: mqtt
name: "Tasmota Switch 3"
state_topic: "stat/tasmota/RESULT"
value_template: "{{ value_json.POWER3 }}"
command_topic: "cmnd/tasmota/POWER3"
payload_on: "ON"
payload_off: "OFF"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! example "Dimmer" Used for dimmers and dimmable lights (single channel lights).
light:
- platform: mqtt
name: "Dimmer"
command_topic: "cmnd/tasmota/POWER"
state_topic: "tele/tasmota/STATE"
state_value_template: "{{value_json.POWER}}"
availability_topic: "tele/tasmota/LWT"
brightness_command_topic: "cmnd/tasmota/Dimmer"
brightness_state_topic: "tele/tasmota/STATE"
brightness_scale: 100
on_command_type: "brightness"
brightness_value_template: "{{value_json.Dimmer}}"
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! tip
If you are using your device to control a light, you may want to use MQTT Light
integration instead.
Simply replace switch:
with light:
in the configuration keeping everything else the same.
Add in Home Assistant using the MQTT Light integration.
Required Commands
SetOption17 1
- enables decimal colors
SetOption59 1
- enables sending of tele/%topic%/STATE on POWER and light related commands
Optional Commands
Fade on
- makes transitions smoother
Speed 5
- sets transition speed
!!! example "Dimming" Used for dimmers and dimmable lights (single channel lights).
light:
- platform: mqtt
name: "Dimmer"
command_topic: "cmnd/tasmota/POWER"
state_topic: "tele/tasmota/STATE"
state_value_template: "{{value_json.POWER}}"
availability_topic: "tele/tasmota/LWT"
brightness_command_topic: "cmnd/tasmota/Dimmer"
brightness_state_topic: "tele/tasmota/STATE"
brightness_scale: 100
on_command_type: "brightness"
brightness_value_template: "{{value_json.Dimmer}}"
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! example "RGB Light"
light:
- platform: mqtt
name: "RGB Light"
command_topic: "cmnd/tasmota/POWER"
state_topic: "tele/tasmota/STATE"
state_value_template: "{{value_json.POWER}}"
availability_topic: "tele/tasmota/LWT"
brightness_command_topic: "cmnd/tasmota/Dimmer"
brightness_state_topic: "tele/tasmota/STATE"
brightness_scale: 100
on_command_type: "brightness"
brightness_value_template: "{{value_json.Dimmer}}"
rgb_command_topic: "cmnd/tasmota/Color2"
rgb_state_topic: "tele/tasmota/STATE"
rgb_value_template: "{{value_json.Color.split(',')[0:3]|join(',')}}"
effect_command_topic: "cmnd/tasmota/Scheme"
effect_state_topic: "tele/tasmota/STATE"
effect_value_template: "{{value_json.Scheme}}"
effect_list:
- 0
- 1
- 2
- 3
- 4
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! example "RGB+W Light"
light:
- platform: mqtt
name: "RGB+W Light"
command_topic: "cmnd/tasmota/POWER"
state_topic: "tele/tasmota/STATE"
state_value_template: "{{value_json.POWER}}"
availability_topic: "tele/tasmota/LWT"
brightness_command_topic: "cmnd/tasmota/Dimmer"
brightness_state_topic: "tele/tasmota/STATE"
brightness_scale: 100
on_command_type: "brightness"
brightness_value_template: "{{value_json.Dimmer}}"
white_value_state_topic: "tele/tasmota/STATE"
white_value_command_topic: "cmnd/tasmota/White"
white_value_scale: 100
white_value_template: "{{ value_json.Channel[3] }}"
rgb_command_topic: "cmnd/tasmota/Color2"
rgb_state_topic: "tele/tasmota/STATE"
rgb_value_template: "{{value_json.Color.split(',')[0:3]|join(',')}}"
effect_command_topic: "cmnd/tasmota/Scheme"
effect_state_topic: "tele/tasmota/STATE"
effect_value_template: "{{value_json.Scheme}}"
effect_list:
- 0
- 1
- 2
- 3
- 4
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! example "RGB+CCT Light" Also known as RGBWW or 5 channel lights
light:
- platform: mqtt
name: "RGBCCT Light"
command_topic: "cmnd/tasmota/POWER"
state_topic: "tele/tasmota/STATE"
state_value_template: "{{value_json.POWER}}"
availability_topic: "tele/tasmota/LWT"
brightness_command_topic: "cmnd/tasmota/Dimmer"
brightness_state_topic: "tele/tasmota/STATE"
brightness_scale: 100
on_command_type: "brightness"
brightness_value_template: "{{value_json.Dimmer}}"
color_temp_command_topic: "cmnd/tasmota/CT"
color_temp_state_topic: "tele/tasmota/STATE"
color_temp_value_template: "{{value_json.CT}}"
rgb_command_topic: "cmnd/tasmota/Color2"
rgb_state_topic: "tele/tasmota/STATE"
rgb_value_template: "{{value_json.Color.split(',')[0:3]|join(',')}}"
effect_command_topic: "cmnd/tasmota/Scheme"
effect_state_topic: "tele/tasmota/STATE"
effect_value_template: "{{value_json.Scheme}}"
effect_list:
- 0
- 1
- 2
- 3
- 4
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! example "Addressable LED"
Applies only to WS281x lights.
light:
- platform: mqtt
name: "Addressable LED"
command_topic: "cmnd/tasmota/POWER"
state_topic: "stat/tasmota/STATE"
state_value_template: "{{value_json.POWER}}"
availability_topic: "tele/tasmota/LWT"
brightness_command_topic: "cmnd/tasmota/Dimmer"
brightness_state_topic: "stat/tasmota/STATE"
brightness_scale: 100
on_command_type: "brightness"
brightness_value_template: "{{value_json.Dimmer}}"
rgb_command_topic: "cmnd/tasmota/Color2"
rgb_state_topic: "tele/tasmota/STATE"
rgb_value_template: "{{value_json.Color.split(',')[0:3]|join(',')}}"
effect_command_topic: "cmnd/tasmota/Scheme"
effect_state_topic: "stat/tasmota/STATE"
effect_value_template: "{{value_json.Scheme}}"
effect_list:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
retain: false
!!! example "No SetOption17 RGB"
If you don't want to use SetOption17 1
you can change
rgb_value_template: "{{value_json.Color.split(',')[0:3]|join(',')}}"
to
rgb_value_template: "{% if value_json.Color is defined %}{{ (value_json.Color[0:2]|int(base=16),value_json.Color[2:4]|int(base=16),value_json.Color[4:6]|int(base=16)) | join(',')}}{% endif %}"
Add in Home Assistant using the MQTT Sensor integration.
A sensor will send its data in set intervals defined by TelePeriod
(default every 5 minutes).
!!! example "Temperature"
Check your sensor name in Tasmota and change accordingly. This example uses the DHT22 sensor.
sensor:
- platform: mqtt
name: "Tasmota Temperature"
state_topic: "tele/tasmota/SENSOR"
value_template: "{{ value_json['DHT22'].Temperature }}"
unit_of_measurement: "°C" # "F" if using Fahrenheit
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
device_class: temperature
!!! example "Humidity"
Check your sensor name in Tasmota and change accordingly. This example uses the DHT22 sensor.
sensor:
- platform: mqtt
name: "Tasmota Humidity"
state_topic: "tele/tasmota/SENSOR"
value_template: "{{ value_json['DHT22'].Humidity }}"
unit_of_measurement: "%"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
device_class: humidity
!!! example "Pressure" Check your sensor name in Tasmota and change accordingly. This example uses the BMP280 sensor.
sensor:
- platform: mqtt
name: "Tasmota Pressure"
state_topic: "tele/tasmota/SENSOR"
value_template: "{{ value_json.BMP280.Pressure }}"
unit_of_measurement: "hPa"
device_class: pressure
Change unit_of_measurement to "mmHg"
if SetOption24 1
!!! example "Wi-Fi Signal Quality"
Monitor the relative Wi-Fi signal quality of a device.
sensor:
- platform: mqtt
name: "Tasmota Wi-Fi Quality"
state_topic: "tele/tasmota/STATE"
unit_of_measurement: "%"
value_template: "{{value_json['Wifi'].RSSI }}"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
device_class: signal_strength
Add in Home Assistant using the MQTT Sensor integration.
Power monitoring sensors will send their data in set intervals defined by TelePeriod
(default every 5 minutes).
To get all the data in Home Assistant requires multiple sensors which you can later group to your liking in Lovelace UI
!!! example "Power Monitoring"
sensor:
- platform: mqtt
name: "Energy Today"
state_topic: "tele/tasmota/SENSOR"
value_template: '{{ value_json["ENERGY"]["Today"] }}'
unit_of_measurement: "kWh"
- platform: mqtt
name: "Power"
state_topic: "tele/tasmota/SENSOR"
value_template: '{{ value_json["ENERGY"]["Power"] }}'
unit_of_measurement: "W"
- platform: mqtt
name: "Voltage"
state_topic: "tele/tasmota/SENSOR"
value_template: '{{ value_json["ENERGY"]["Voltage"] }}'
unit_of_measurement: "V"
- platform: mqtt
name: "Current"
state_topic: "tele/tasmota/SENSOR"
value_template: '{{ value_json["ENERGY"]["Current"] }}'
unit_of_measurement: "A"
!!! tip
For additional sensors use "Total";"Yesterday";"Period","ApparentPower","ReactivePower";"Factor" in value_template
string
Video tutorial on a power monitoring plug setup by Digiblur
Add in Home Assistant using the MQTT Binary Sensor integration.
!!! example "PIR Sensor"
Used for a configured PIR Sensor and requires this rule:
Required Commands
Rule1 on Switch1#State=1 do Publish stat/hall/MOTION ON endon on Switch1#State=1 do Publish stat/hall/MOTION OFF endon
Rule1 1
binary_sensor:
- platform: mqtt
name: "Tasmota Motion Sensor"
state_topic: "stat/tasmota/MOTION"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
device_class: motion
qos: 1
!!! example "Door Sensor"
Requires a reed switch configured in Tasmota.
Required Commands
Rule1 on Switch1#State=1 do Publish stat/hall/MOTION ON endon on Switch1#State=1 do Publish stat/hall/MOTION OFF endon
Rule1 1
binary_sensor:
- platform: mqtt
name: "Tasmota Motion Sensor"
state_topic: "stat/tasmota/MOTION"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
device_class: door # also: window, garage_door or opening
qos: 1
!!! example "RF Bridge"
An RF door sensor configured with an RF receiver in Tasmota.
binary_sensor:
- platform: mqtt
name: "RF bridge rfkey"
payload_on: "1"
payload_off: "0"
device_class: opening
state_topic: "tele/tasmota/RESULT"
value_template: '{{ value_json.RfReceived.RfKey }}'
Add in Home Assistant using the MQTT Fan integration.
!!! example "Fan"
Derived from #2839 by @kbickar and @finity69x2
# Example configuration.yaml entry
fan:
- platform: mqtt
name: "Tasmota Fan"
command_topic: "cmnd/tasmota/FanSpeed"
speed_command_topic: "cmnd/tasmota/FanSpeed"
state_topic: "stat/tasmota/RESULT"
speed_state_topic: "stat/tasmota/RESULT"
state_value_template: >
{% if value_json.FanSpeed is defined %}
{% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
{% else %}
{% if states.fan.tasmota.state == 'off' -%}0{%- elif states.fan.tasmota.state == 'on' -%}4{%- endif %}
{% endif %}
speed_value_template: "{{ value_json.FanSpeed }}"
availability_topic: tele/tasmota/LWT
payload_off: "0"
payload_on: "4"
payload_low_speed: "1"
payload_medium_speed: "2"
payload_high_speed: "3"
payload_available: Online
payload_not_available: Offline
speeds:
- off
- low
- medium
- high
!!! example "iFan02" Combination of configs found in issue #2839 and Home Assistant forum thread Sonoff IFan02 (Tasmota) MQTT Fan.
fan:
- platform: mqtt
name: "Pat Ceiling Fan"
state_topic: "stat/ifan02/RESULT"
speed_state_topic: "stat/ifan02/RESULT"
state_value_template: >
{% if value_json.FanSpeed is defined %}
{% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}2{%- endif %}
{% else %}
{% if states.fan.pat_ceiling_fan.state == 'off' -%}0{%- elif states.fan.pat_ceiling_fan.state == 'on' -%}2{%- endif %}
{% endif %}
speed_value_template: "{{ value_json.FanSpeed }}"
availability_topic: tele/ifan02/LWT
payload_available: Online
payload_not_available: Offline
speed_command_topic: "cmnd/ifan02/FanSpeed"
payload_low_speed: "1"
payload_medium_speed: "2"
payload_high_speed: "3"
command_topic: "cmnd/ifan02/FanSpeed"
payload_off: "0"
payload_on: "2"
qos: 1
retain: false
speeds:
- low
- medium
- high
light:
- platform: mqtt
name: "Pat Ceiling Light"
state_topic: "tele/ifan02/STATE"
value_template: "{{ value_json.POWER }}"
command_topic: "cmnd/ifan02/POWER"
availability_topic: "tele/ifan02/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
!!! example "Sonoff S31"
Configure the device as Sonoff S31, and run:
SetOption4 1
SetOption59 1
switch:
- platform: mqtt
name: "s31 power"
state_topic: "tele/s31/STATE"
value_template: "{{ value_json.POWER }}"
command_topic: "cmnd/s31/POWER"
availability_topic: "tele/s31/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
sensor:
- platform: mqtt
name: "s31 Voltage"
state_topic: "tele/s31/SENSOR"
value_template: "{{ value_json['ENERGY'].Voltage }}"
unit_of_measurement: "V"
availability_topic: "tele/s31/LWT"
qos: 1
payload_available: "Online"
payload_not_available: "Offline"
- platform: mqtt
name: "s31 Current"
state_topic: "tele/s31/SENSOR"
value_template: "{{ value_json['ENERGY'].Current | round(2) }}"
unit_of_measurement: "A"
availability_topic: "tele/s31/LWT"
qos: 1
payload_available: "Online"
payload_not_available: "Offline"
- platform: mqtt
name: "s31 Power"
state_topic: "tele/s31/SENSOR"
value_template: "{{ value_json['ENERGY'].Power }}"
unit_of_measurement: "W"
availability_topic: "tele/s31/LWT"
qos: 1
payload_available: "Online"
payload_not_available: "Offline"
device_class: power
- platform: mqtt
name: "s31 Power Factor"
state_topic: "tele/s31/SENSOR"
value_template: "{{ value_json['ENERGY'].Factor }}"
availability_topic: "tele/s31/LWT"
qos: 1
payload_available: "Online"
payload_not_available: "Offline"
- platform: mqtt
name: "s31 Energy Today"
state_topic: "tele/s31/SENSOR"
value_template: "{{ value_json['ENERGY'].Today }}"
unit_of_measurement: "kWh"
availability_topic: "tele/s31/LWT"
qos: 1
payload_available: "Online"
payload_not_available: "Offline"
- platform: mqtt
name: "s31 Energy Yesterday"
state_topic: "tele/s31/SENSOR"
value_template: "{{ value_json['ENERGY'].Yesterday }}"
unit_of_measurement: "kWh"
availability_topic: "tele/s31/LWT"
qos: 1
payload_available: "Online"
payload_not_available: "Offline"
- platform: mqtt
name: "s31 Energy Total"
state_topic: "tele/s31/SENSOR"
value_template: "{{ value_json['ENERGY'].Total }}"
unit_of_measurement: "kWh"
availability_topic: "tele/s31/LWT"
qos: 1
payload_available: "Online"
payload_not_available: "Offline"
!!! example "Dimmable Light"
This configuration is for a dimmable light reporting on 0xE1F9
using endpoint 1, cluster 8 for brightness. ZbRead
part in the template is needed to always update the brightness values.
# Example configuration.yaml entry
light:
- platform: mqtt
schema: template
name: "Fire Light"
command_topic: "cmnd/zigbee-gateway/Backlog"
state_topic: "tele/zigbee-gateway/SENSOR"
command_on_template: >
{%- if brightness is defined -%}
ZbSend { "device":"0xE1F9", "send":{"Dimmer":{{ brightness }} } }; ZbSend { "device":"0xE1F9", "send":{"Power":true} }; delay 20; ZbRead { "device":"0xE1F9", "endpoint":1, "cluster":8, "read":0 }
{%- else -%}
ZbSend { "device":"0xE1F9", "send":{"Power":true} }; delay 20; ZbRead { "device":"0xE1F9", "endpoint":1, "cluster":8, "read":0 }
{%- endif -%}
command_off_template: 'ZbSend { "device":"0xE1F9", "send":{"Power":false} }; delay 20; ZbRead { "device":"0xE1F9", "endpoint":1, "cluster":8, "read":0 }'
state_template: >
{% if value_json.ZbReceived is defined and value_json.ZbReceived['0xE1F9'] is defined and value_json.ZbReceived['0xE1F9'].Power is defined %}
{% if value_json.ZbReceived['0xE1F9'].Power == true %}
on
{% else %}
off
{% endif %}
{% else %}
{{ states('light.fire_light') }}
{% endif %}
brightness_template: >
{%- if value_json.ZbReceived is defined and value_json.ZbReceived['0xE1F9'] is defined and value_json.ZbReceived['0xE1F9'].Dimmer is defined -%}
{{ value_json['ZbReceived']['0xE1F9'].Dimmer | int }}
{%- else -%}
{{ state_attr('light.fire_light', 'brightness') | int }}
{%- endif -%}
!!! example "Water Leak Sensor"
This specific configuration is for Xiaomi Aqara Water Leak sensor reporting on 0x099F
.
# Example configuration.yaml entry
binary_sensor:
- platform: mqtt
name: "Water Leak"
state_topic: "tele/zigbee-gateway/SENSOR"
value_template: >
{%- if value_json.ZbReceived is defined and value_json.ZbReceived['0x099F'] is defined -%}
{%- if value_json.ZbReceived['0x099F']['0500!00'] == '010000FF0000' -%}
ON
{% else %}
OFF
{% endif %}
{% else %}
{{ states('binary_sensor.water_leak') }}
{% endif %}
availability_topic: "tele/zigbee-gateway/LWT"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
device_class: moisture
!!! example "Enable join switch"
- platform: mqtt
name: Zigbee2Tasmota enable join
state_topic: "tele/zigbee/RESULT"
command_topic: "cmnd/zigbee/ZbPermitJoin"
payload_on: "1"
payload_off: "0"
state_on: "Enable Pairing mode for 60 seconds"
state_off: "off"
optimistic: false
qos: 1
retain: false
value_template: '{{value_json.ZbState.Message }}'
icon: mdi:zigbee
!!! example "Extended device information"
Wi-Fi signal quality can be added as a parameter to any previous configuration by appending this section to the existing configuration yaml
json_attributes_topic: "tele/tasmota/STATE"
json_attributes_template: "{{ value_json.Wifi | tojson }}"
!!! example "Sync Power State"
When MQTT broker or Home Assistant is restarted, or there is a WiFi outage, Tasmota device states may not be synced with Home Assistant. Use this automation to keep your devices in sync, including power state, immediately after Home Assistant is started.
automation:
- id: Sync Tasmota states
alias: Sync Tasmota states
initial_state: true
trigger:
platform: homeassistant
event: start
action:
# sync state for devices with default fulltopics
- service: mqtt.publish
data:
topic: cmnd/tasmotas/state
payload: ''
# sync state for autodiscovery devices
- service: mqtt.publish
data:
topic: tasmotas/cmnd/state
payload: ''
To sync a single TuyaMCU device states add this block with your %topic% to the automation. !!! bug
You could use tasmotas
but SerialSend might cause issues on other devices so proceed with caution.
- service: mqtt.publish
data:
topic: cmnd/%topic%/serialsend5
payload: 55aa0001000000
Sync Zigbee device states. Add this block with your %topic% and your Zigbee device name, endpoint and cluster.
!!! example "Example for a dimmable light"
- service: mqtt.publish
data:
topic: cmnd/zigbee-gateway/Backlog
payload: ZbRead { "device":"0xE1F9", "endpoint":1, "cluster":6, "read":0 }; delay 5; ZbRead { "device":"0xE1F9", "endpoint":1, "cluster":8, "read":0 }
!!! example "Report Firmware Version"
Add a sensor like below for each Tasmota device whose firmware version you want to track.
# Example configuration.yaml entry
sensor:
- platform: mqtt
name: "Tasmota"
state_topic: "stat/tasmota/STATUS2"
value_template: "{{value_json['StatusFWR'].Version }}"
availability_topic: "tele/tasmota/LWT"
payload_available: "Online"
payload_not_available: "Offline"
qos: 0
Automation to have each device report firmware version on Home Assistant reboot. You can manually trigger this automation from Home Assistant UI.
automation:
- alias: "Tasmota Firmware Version Check"
trigger:
platform: homeassistant
event: start
action:
- service: mqtt.publish
data:
topic: "cmnd/tasmotas/STATUS"
payload: "2"
!!! tip
If you want all your devices to switch to autodiscovery method go through Developer tools - MQTT by publishing to grouptopic cmnd/tasmotas/SetOption19
with payload 1