Combine MQTT Switch and Binary Sensor

I thought it might be worth trying but I agree with you, the component is waiting for a payload to arrive via the state_topic before it applies the value_template.

An easy workaround is to use a simple automation to make binary_sensor.alarm_monitor_0_13 publish its state to an MQTT topic (such as right-garage/status).

- alias: 'MQTT Alarm Monitor 13'
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.alarm_monitor_0_13
  action:
    service: mqtt.publish
    data_template:
      topic: 'right-garage/status'
      payload: "{{ 'open' if trigger.to_state.state == 'on' else 'closed' }}"

Using the automation, the cover’s configuration is simplified to this:

cover:
  - platform: mqtt
    name: garage_door_right
    device_class: garage
    state_topic: 'right-garage/status'
    command_topic: 'right-garage/button'
    payload_open: 'OPEN'
    payload_close: 'OPEN'
    payload_stop: 'OPEN'
1 Like