I’d like to post a good recommendation on how to do the new mqtt syntax
First create a directory called mqtt in the config folder of Home Assistant
In configuration.yaml add this one line
mqtt: !include_dir_merge_named mqtt
For each old “platform” create a file. You can name it anything but it must end with .yaml
and it makes sense to make e.g. a file called mqtt-lights.yaml
I chose to prefix my file names with “mqtt-” because if I get an error in the yaml check I can clearly see in the log if it is the old sensors.yaml file which you may still have for other non-mqtt platforms or the new mqtt-sensors.yaml that contains the syntax error
And inside the file the format will be (ignore that I have a ventillator I pretend it s light)
light:
- name: "Bedroom Ventilator"
unique_id: "Bedroom Ventilator as Light"
state_topic: "bedroom-ventilator/state"
command_topic: "bedroom-ventilator/set"
brightness_state_topic: "bedroom-ventilator/speed/state"
brightness_command_topic: "bedroom-ventilator/speed/set"
payload_on: "on"
payload_off: "off"
retain: "on"
icon: "mdi:fan"
- name: Magic Mirror
unique_id: "Magic Mirror"
command_topic: "magicmirror/set"
state_topic: "magicmirror/state"
payload_on: "on"
payload_off: "off"
and for a few more examples
a file called mqtt-sensor.yaml
sensor:
- name: "nfcmqtt"
state_topic: "alarm/nfcid"
unique_id: "nfcmqtt"
- name: "Bathroom Rising"
state_topic: "fan/rising"
unique_id: "Bathroom Rising"
unit_of_measurement: '%'
- name: "Bathroom Falling"
state_topic: "fan/falling"
unique_id: "Bathroom Falling"
unit_of_measurement: '%'
- name: "Bathroom Humidity"
state_topic: "fan/humidity"
unique_id: "Bathroom Humidity"
unit_of_measurement: '%'
- name: "Fan Temperature"
unique_id: "Fan Temperature"
state_topic: "fan/temperature"
unit_of_measurement: '°C'
and same with mqtt-binary-sensor.yaml
binary_sensor:
- name: "Mailbox"
state_topic: "mailserver/state"
unique_id: "Mailbox sensor"
payload_on: "on"
payload_off: "off"
- name: "Bed Sensor Kenneth"
state_topic: "bedsensor/state/kenneth"
unique_id: "Bed Sensor Kenneth"
payload_on: "on"
payload_off: "off"
- name: "Bed Sensor Diane"
state_topic: "bedsensor/state/diane"
unique_id: "Bed Sensor Diane"
payload_on: "on"
payload_off: "off"
- name: "Front Door"
state_topic: "sensor/frontdoor"
unique_id: "Front Door Sensor"
payload_on: "on"
payload_off: "off"
device_class: "door"
Here is one for blinds mqtt-blinds.yaml
cover:
- name: "Left Blinds"
unique_id: "Left Blinds"
command_topic: "blinds/set/left"
state_topic: "blinds/position/left"
position_topic: "blinds/position/left"
set_position_topic: "blinds/set/left"
retain: false
payload_open: "50"
payload_close: "0"
payload_stop: "85"
state_open: "50"
state_closed: "0"
optimistic: false
device_class: blind
- name: "Right Blinds"
unique_id: "Right Blinds"
command_topic: "blinds/set/right"
state_topic: "blinds/position/right"
position_topic: "blinds/position/right"
set_position_topic: "blinds/set/right"
retain: false
payload_open: "50"
payload_close: "0"
payload_stop: "85"
state_open: "50"
state_closed: "0"
optimistic: false
device_class: blind
- name: "Office Blinds"
unique_id: "Office Blinds"
command_topic: "office-blinds/set"
state_topic: "office-blinds/position"
position_topic: "office-blinds/position"
set_position_topic: "office-blinds/set"
retain: false
payload_open: "50"
payload_close: "0"
payload_stop: "85"
state_open: "50"
state_closed: "0"
optimistic: false
device_class: blind
And here are some device_trackers in a mqtt-device-tracker.yaml
Note that device_trackers do not get loaded unless you restart Home Assistant. This is a known bug and there is a PR in the pipe line for this
device_tracker:
- name: "BLE Button Kenneth1"
unique_id: "ble-button-kenneth1"
state_topic: "blescan/1/kenneth"
payload_home: "on"
payload_not_home: "off"
source_type: "bluetooth_le"
- name: "BLE Button Diane1"
state_topic: "blescan/1/diane"
unique_id: "ble-button-diane1"
payload_home: "on"
payload_not_home: "off"
source_type: "bluetooth_le"
- name: "BLE Button Kenneth2"
state_topic: "blescan/2/kenneth"
unique_id: "ble-button-kenneth2"
payload_home: "on"
payload_not_home: "off"
source_type: "bluetooth_le"
- name: "BLE Button Diane2"
state_topic: "blescan/2/diane"
unique_id: "ble-button-diane2"
payload_home: "on"
payload_not_home: "off"
source_type: "bluetooth_le"
Here are fans mqtt-fans.yaml
fan:
- name: "Fan"
unique_id: "Fan Bathroom"
state_topic: "fan/state"
command_topic: "fan/set"
payload_on: "on"
payload_off: "off"
- name: "Utility Fan"
unique_id: "Utility Fan"
state_topic: "utility-fan/state"
command_topic: "utility-fan/set"
payload_on: "on"
payload_off: "off"
And then some switches in a mqtt-switches.yaml
switch:
- name: "Short Toilet Flush"
unique_id: "Short Toilet Flush"
state_topic: "toiletflushshort/state"
command_topic: "toiletflushshort/set"
payload_on: "ON"
payload_off: "OFF"
state_on: "ON"
state_off: "OFF"
optimistic: false
qos: 0
retain: false
- name: "Long Toilet Flush"
unique_id: "Long Toilet Flush"
state_topic: "toiletflushlong/state"
command_topic: "toiletflushlong/set"
payload_on: "ON"
payload_off: "OFF"
state_on: "ON"
state_off: "OFF"
optimistic: false
qos: 0
retain: false
This is a long post. But I know that what people really need is real life working examples and not condensed documentation.