MQTT Cover


The mqtt cover platform allows you to control an MQTT cover (such as blinds, a rollershutter or a garage door).

Configuration

The device state (open, opening, closed or closing) will be updated only after a new message is published on state_topic matching state_open, state_opening, state_closed or state_closing. If these messages are published with the retain flag set, the cover will receive an instant state update after subscription and Home Assistant will display the correct state on startup. Otherwise, the initial state displayed in Home Assistant will be unknown. state_topic can only manage state_open, state_opening, state_closed and state_closing. No percentage positions etc.

For this purpose is position_topic which can set state of the cover and position. Default setting are 0 means the device is closed and all other intermediate positions means the device is open. position_topic is managed by position_open and position_closed You can set it up in opposite way as well. If position topic is defined than state topic is ignored.

If a state topic and position topic are not defined, the cover will work in optimistic mode. In this mode, the cover will immediately change state (open or closed) after every command sent by Home Assistant. If a state topic/position topic is defined, the cover will wait for a message on state_topic or position_topic.

Optimistic mode can be forced, even if a state_topic / position_topic is defined. Try to enable it if experiencing incorrect cover operation (Google Assistant gauge may need optimistic mode as it often send request to your Home Assistant immediately after send set_cover_position in which case MQTT could be too slow).

The mqtt cover platform optionally supports a list of availability topics to receive online and offline messages (birth and LWT messages) from the MQTT cover device. During normal operation, if the MQTT cover device goes offline (i.e., publishes a matching payload_not_available to any availability topic), Home Assistant will display the cover as “unavailable”. If these messages are published with the retain flag set, the cover will receive an instant update after subscription and Home Assistant will display correct availability state of the cover when Home Assistant starts up. If the retain flag is not set, Home Assistant will display the cover as “unavailable” when Home Assistant starts up.

To use your MQTT cover in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
cover:
  - platform: mqtt
    command_topic: "home-assistant/cover/set"

Configuration Variables

availabilitylist(Optional)

A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with availability_topic.

payload_availablestring(Optional, default: online)

The payload that represents the available state.

payload_not_availablestring(Optional, default: offline)

The payload that represents the unavailable state.

topicstringRequired

An MQTT topic subscribed to receive availability (online/offline) updates.

availability_topicstring(Optional)

The MQTT topic subscribed to to receive birth and LWT messages from the MQTT cover device. If an availability topic is not defined, the cover availability state will always be available. If an availability topic is defined, the cover availability state will be unavailable by default. Must not be used together with availability.

command_topicstring(Optional)

The MQTT topic to publish commands to control the cover.

devicemap(Optional)

Information about the device this cover is a part of to tie it into the device registry. Only works through MQTT discovery and when unique_id is set.

connectionslist(Optional)

A list of connections of the device to the outside world as a list of tuples [connection_type, connection_identifier]. For example the MAC address of a network interface: "connections": ["mac", "02:5b:26:a8:dc:12"].

identifierslist | string(Optional)

A list of IDs that uniquely identify the device. For example a serial number.

manufacturerstring(Optional)

The manufacturer of the device.

modelstring(Optional)

The model of the device.

namestring(Optional)

The name of the device.

sw_versionstring(Optional)

The firmware version of the device.

via_devicestring(Optional)

Identifier of a device that routes messages between this device and Home Assistant. Examples of such devices are hubs, or parent devices of a sub-device. This is used to show device topology in Home Assistant.

device_classstring(Optional)

Sets the class of the device, changing the device state and icon that is displayed on the frontend.

json_attributes_templatetemplate(Optional)

Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation.

json_attributes_topicstring(Optional)

The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation.

namestring(Optional, default: MQTT Cover)

The name of the cover.

optimisticstring(Optional)

Flag that defines if switch works in optimistic mode.

Default:

true if no state topic defined, else false.

payload_availablestring(Optional, default: online)

The payload that represents the online state.

payload_closestring(Optional, default: CLOSE)

The command payload that closes the cover.

payload_not_availablestring(Optional, default: offline)

The payload that represents the offline state.

payload_openstring(Optional, default: OPEN)

The command payload that opens the cover.

payload_stopstring(Optional, default: STOP)

The command payload that stops the cover.

position_closedinteger(Optional, default: 0)

Number which represents closed position.

position_openinteger(Optional, default: 100)

Number which represents open position.

position_topicstring(Optional)

The MQTT topic subscribed to receive cover position messages. If position_topic is set state_topic is ignored.

qosinteger(Optional, default: 0)

The maximum QoS level to be used when receiving and publishing messages.

retainboolean(Optional, default: false)

Defines if published messages should have the retain flag set.

set_position_templatestring(Optional)

Defines a template to define the position to be sent to the set_position_topic topic. Incoming position value is available for use in the template ``. If no template is defined, the position (0-100) will be calculated according to position_open and `position_closed` values.

set_position_topicstring(Optional)

The MQTT topic to publish position commands to. You need to set position_topic as well if you want to use position topic. Use template if position topic wants different values than within range position_closed - position_open. If template is not defined and position_closed != 100 and position_open != 0 then proper position value is calculated from percentage position.

state_closedstring(Optional, default: closed)

The payload that represents the closed state.

state_closingstring(Optional, default: closing)

The payload that represents the closing state.

state_openstring(Optional, default: open)

The payload that represents the open state.

state_openingstring(Optional, default: opening)

The payload that represents the opening state.

state_topicstring(Optional)

The MQTT topic subscribed to receive cover state messages. Use only if not using position_topic. State topic can only read open/close state. Cannot read position state. If position_topic is set state_topic is ignored.

tilt_closed_valueinteger(Optional, default: 0)

The value that will be sent on a close_cover_tilt command.

tilt_command_topicstring(Optional)

The MQTT topic to publish commands to control the cover tilt.

tilt_invert_stateboolean(Optional, default: false)

Flag that determines if open/close are flipped; higher values toward closed and lower values toward open.

tilt_maxinteger(Optional, default: 100)

The maximum tilt value

tilt_mininteger(Optional, default: 0)

The minimum tilt value.

tilt_opened_valueinteger(Optional, default: 100)

The value that will be sent on an open_cover_tilt command.

tilt_optimisticboolean(Optional)

Flag that determines if tilt works in optimistic mode.

Default:

true if tilt_status_topic is not defined, else false

tilt_status_templatestring(Optional)

Defines a template that can be used to extract the payload for the tilt_status_topic topic.

tilt_status_topicstring(Optional)

The MQTT topic subscribed to receive tilt status update values.

unique_idstring(Optional)

An ID that uniquely identifies this cover. If two covers have the same unique ID, Home Assistant will raise an exception.

value_templatestring(Optional)

Defines a template to extract a value from the payload.

Examples

In this section you will find some real-life examples of how to use this platform.

Full configuration state topic without tilt

The example below shows a full configuration for a cover without tilt with state topic only.

# Example configuration.yaml entry
cover:
  - platform: mqtt
    name: "MQTT Cover"
    command_topic: "home-assistant/cover/set"
    state_topic: "home-assistant/cover/state"
    availability:
      - topic: "home-assistant/cover/availability"
    qos: 0
    retain: true
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STOP"
    state_open: "open"
    state_opening: "opening"
    state_closed: "closed"
    state_closing: "closing"
    payload_available: "online"
    payload_not_available: "offline"
    optimistic: false
    value_template: '{{ value.x }}'

Full configuration position topic without tilt

The example below shows a full configuration for a cover without tilt with position topic.

# Example configuration.yaml entry
cover:
  - platform: mqtt
    name: "MQTT Cover"
    command_topic: "home-assistant/cover/set"
    position_topic: "home-assistant/cover/position"
    availability:
      - "home-assistant/cover/availability"
    set_position_topic: "home-assistant/cover/set_position"
    qos: 0
    retain: true
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STOP"
    position_open: 100
    position_closed: 0
    payload_available: "online"
    payload_not_available: "offline"
    optimistic: false
    value_template: '{{ value.x }}'

Full configuration

The example below shows a full configuration for a cover.

# Example configuration.yaml entry
cover:
  - platform: mqtt
    name: "MQTT Cover"
    command_topic: "home-assistant/cover/set"
    state_topic: "home-assistant/cover/state"
    availability:
      - topic: "home-assistant/cover/availability"
    qos: 0
    retain: true
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STOP"
    state_open: "open"
    state_opening: "opening"
    state_closed: "closed"
    state_closing: "closing"
    payload_available: "online"
    payload_not_available: "offline"
    optimistic: false
    value_template: '{{ value.x }}'
    tilt_command_topic: 'home-assistant/cover/tilt'
    tilt_status_topic: 'home-assistant/cover/tilt-state'
    tilt_status_template: '{{ value_json["PWM"]["PWM1"] }}'
    tilt_min: 0
    tilt_max: 180
    tilt_closed_value: 70
    tilt_opened_value: 180

To test, you can use the command line tool mosquitto_pub shipped with mosquitto or the mosquitto-clients package to send MQTT messages. This allows you to operate your cover manually:

mosquitto_pub -h 127.0.0.1 -t home-assistant/cover/set -m "CLOSE"