Mqtt cover garage door

Hi There,

Having issues getting my relay to switch on using a Tasmota - MQTT broker, and looking for some guidance.

The issue I’m facing has to do with the relay state. When I look at the web console for my “rollerdoor1” device I see the following

23:25:15 MQT: stat/rollerdoor1/POWER = OFF (retained)
23:25:31 MQT: stat/rollerdoor1/RESULT = {“POWER”:“OFF”}

When I enter “cmnd/rollerdoor1/power on” into the console the relay activates as it should on for one second then off again but can’t seem to make that happen from Home Assistant

23:48:52 CMD: cmnd/rollerdoor1/power on
23:48:52 MQT: stat/rollerdoor1/RESULT = {“POWER”:“ON”}
23:48:52 MQT: stat/rollerdoor1/POWER = ON (retained)
23:48:53 MQT: stat/rollerdoor1/RESULT = {“POWER”:“OFF”}
23:48:53 MQT: stat/rollerdoor1/POWER = OFF (retained)

I tried to add the “on” switch to the “command_topic” in the home assistant cover.yaml file but that didn’t work

command_topic: “cmnd/rollerdoor1/POWER ON” - no good didn’t work

currently, I have the following set in my cover.yaml file which returns when I activate the arrow inlovelace
command_topic: “cmnd/rollerdoor1/POWER”
state_topic: “stat/rollerdoor1/POWER”

cover

23:25:15 MQT: stat/rollerdoor1/POWER = OFF (retained)
23:25:31 MQT: stat/rollerdoor1/RESULT = {“POWER”:“OFF”}

Been stuck on this for a couple of days, please advise?

Hardware - 1 Channel Inching /Self-Locking WiFi Wireless Switch 5V 12V

Sonoff Tasmota config - fileSonoff.xml (36.9 KB)

Cover.yaml config - cover.yaml (399 Bytes)

Customize.yaml config - customize.yaml (855 Bytes)

For future reference, don’t be shy to post configuration data directly as opposed to using an attachment. It makes it easier for others to read.

Here’s your cover configuration:

- platform: mqtt
  name: "mainrollerdoor"
  state_topic: "stat/rollerdoor1/POWER"
  command_topic: "cmnd/rollerdoor1/POWER"
  availability_topic: "tele/rollerdoor1/LWT"
  payload_available: "Online"
  payload_not_available: "Offline"
  payload_open: "OPEN"
  payload_close: "CLOSE"
  payload_stop: "STOP"
  state_open: "open"
  state_closed: "closed"
  optomistic: false
  retain: false

A few minor points:

  • optimistic is misspelled. Just remove this option because optimistic: false is the default and you have already provided a state_topic thereby making optimistic unnecessary.
  • You can also remove retain: false because that’s also the default.

For opening/closing the door, cover publishes to command_topic using whatever you specified for payload_open and payload_close. Based on your configuration, it will publish OPEN and CLOSE to cmnd/rollerdoor1/POWER.

If these are not the correct commands, then change them. I believe you indicated it uses ON and OFF?

FWIW, in my case, the same command is used to both open and close the door so my config looks like this (it’s not using a Sonoff device):

  payload_open: "1"
  payload_close: "1"
  payload_stop: "1"

Thank you 123 for your assistance, only new to Home Assistant and this is my first MQTT controll.

The one thing I didn’t think to adjust was the payload form “open”, “close” and “stop” to “on” or a “1”. Making this change corrected my issue

payload_open: “1”
payload_close: “1”
payload_stop: “1”

image

Thanks for your help

Sorry come up against another issue

the relay now triggers when the up, stop and down buttons are pressed which is great but the state of the door is not showing

image

I have an existing sensor in Home Assistant which shows the roller door state

image
image

but having issues publishing this state to the cover card

- platform: mqtt
  name: "mainrollerdoor"
  state_topic: "home-assistant/sensor/1_garage_door_state"
  command_topic: "cmnd/rollerdoor1/POWER"
  availability_topic: "tele/rollerdoor1/LWT"
  payload_available: "Online"
  payload_not_available: "Offline"
  payload_open: "1"
  payload_close: "1"
  payload_stop: "1"
  state_open: "open"
  state_closed: "closed"

I have taken a look at the MQTT Cover page and I think I have added it correctly but it would seem I missing something
image

Any idea what I’m doing wrong?

You say you have an existing sensor that correctly reports the door’s state.

sensor.1_garage_door_state

Please post the configuration for this sensor. Is it an MQTT Binary Sensor? Does it get its state from the following topic?

home-assistant/sensor/1_garage_door_state

This is not an MQTT sensor this is just a normal binary sensor from my Konnected device which is connected to my Alarm

The current configuration of the “sensor.1_garage_door_state” is as follows

Item in my configuration.yaml file

#Konnected
konnected:
  access_token: !secret Konnected_access_token
  api_host: !secret konnected_ip
  devices:
    - id: !secret konnected_mac
      binary_sensors:
        - zone: 1
          type: door
          name: 1 Garage Door
          inverse: false

Item in my sensor.yaml file

- platform: template
  sensors:
    1_garage_door_state:
      value_template: "{{ 'Closed' if is_state('binary_sensor.1_garage_door', 'off') else 'Open' }}"
      entity_picture_template: '{%- if is_state("binary_sensor.1_garage_door", "off") %}/local/garage.png{% else %}/local/garage-open-blue.png{%- endif %}'         

I was hoping to use an existing binary sensor already configured in HA to report on the state of the door and not the MQTT device I am using to trigger the door motion. To my knowledge, the device I’m currently using only has an option to control a relay and not a sensor as well.

After reading a number of posts, I’m thinking I need to publish this sensor differently to allow MQTT Cover to see the correct state of the door, I just can’t work out how.

Thanks Nick

OK. I now see that sensor.1_garage_door_state is a Template Binary Sensor that derives its state from binary_sensor.1_garage_door which is Konnected binary_sensor.

I suggest you use an automation instead of a Template Binary Sensor.

For example, this automation publishes the state of binary_sensor.1_garage_door to home/garagedoor1.

- alias: 'MQTT Garage Door 1'
  trigger:
    platform: state
    entity_id: binary_sensor.1_garage_door
  action:
  - service: mqtt.publish
    data_template:
      topic: 'home/garagedoor1'
      payload: "{{ 'open' if trigger.payload == 'on' else 'closed' }}"

In the cover’s configuration, set the state_topic to home/garagedoor1.

- platform: mqtt
  name: "mainrollerdoor"
  state_topic: "home/garagedoor1"
  command_topic: "cmnd/rollerdoor1/POWER"
  availability_topic: "tele/rollerdoor1/LWT"
  payload_available: "Online"
  payload_not_available: "Offline"
  payload_open: "1"
  payload_close: "1"
  payload_stop: "1"
  state_open: "open"
  state_closed: "closed"

Now when the Konnected binary_sensor changes state (i.e. detects garage door’s state) it is published to home/garagedoor1 which is the same topic used by the cover to determine the door’s state.

Thank you for your post, I did see the term “mqtt.publish” in some of the posts I read but didn’t make the correlation to my issue.

I have now added the suggested code and it sort of works. If the door is open when I reboot HA it will show correctly but only one way, if the door is closed when HA reboots it doesn’t show the state at all.

In the below image Main and Shed door was closed and Pergola was open at the reboot of HA
image

It seems the sensor state needs to force it’s updated or update more frequently as it doesn’t seem to be updating the arrows correctly.

Because we are representing the state of binary sensor (the Konnected binary sensor), we can safely use retain: true when publishing its state to the MQTT broker.

- alias: 'MQTT Garage Door 1'
  trigger:
    platform: state
    entity_id: binary_sensor.1_garage_door
  action:
  - service: mqtt.publish
    data_template:
      topic: 'home/garagedoor1'
      payload: "{{ 'open' if trigger.payload == 'on' else 'closed' }}"
      retain: true

This will make the MQTT broker store the binary sensor’s state. When Home Assistant restarts it will reconnect to the MQTT broker and get the sensor’s (stored) state.

Thank you once again for your response, adding the “retain” flag indeed helped with the state of the doors after a reboot. Although I’m still not seeing the indicators change when the doors are open, what are your thoughts on this?
image

This has been playing on my mind as it can’t be that difficult to work out but I can’t see it. I had thought it was the binary sensor not sending the change of state through to the cover card, but this is just a simple open/closed sensor and I can see the state change under “Roller Door State”

Is it possible to make the “state_topic” check the sensor state every few minutes?

No, that’s not how MQTT works.

The operating process is very simple.

  • When the door opens/closes, the Konnected binary sensor changes state.
  • This state-change triggers the automation to publish the state-change to home/garagedoor1.
  • The cover’s state_topic is also home/garagedoor1 and so the UI will show when the door open/closes.

If the UI is not indicating the door’s state, something in the process I just described is either improperly configured or works differently from what we expected. To resolve the problem, confirm each step in the process is working.

Start by confirming the Konnected binary sensor always detects and reports the door’s state. Once you are satisfied this sensor is working properly, proceed to confirm the automation is publishing the door’s state to the topic home\garagedoor. If topic’s payload is confirmed to change with the door’s state proceed to confirm the cover is properly configured.

Thank you for your advise.

I can confirm that point one is correct and functioning. I can see the state of the door change when it’s open or closed
image

Point two is a little tricker I have taken a closer look at the MQTT Broker logs and can see the following error appearing in a large part of the log “client id not available”



After some Googling, I have now enabled ACL and Authentication for MQTT and all of the errors are gone.

I am now working on point three, I checked the Automation script you sent from earlier on in the week to make sure that was added correctly and was enabled. I can now confirm that it is
image

I’m still am not seeing the state of the door change but I will keep investigating and report back on my findings.

Thank you for your patience

Nick

Okay have spent the day looking through the HA logs and come across the following

2019-03-28 20:20:40 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home/garagedoor1: b" 'open' if trigger.payload == 'on' else 'closed' "
2019-03-28 20:20:40 WARNING (MainThread) [homeassistant.components.mqtt.cover] Payload is not True or False:  'open' if trigger.payload == 'on' else 'closed' 
2019-03-28 20:20:40 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home/garagedoor2: b" 'open' if trigger.payload == 'true' else 'closed' "
2019-03-28 20:20:40 WARNING (MainThread) [homeassistant.components.mqtt.cover] Payload is not True or False:  'open' if trigger.payload == 'true' else 'closed' 

This is clear that the current payload from the binary sensors binary_sensor.1_garage_door and binary_sensor.2_garage_door is incorrect sending its payload for the current configuration.

I have played with the state_open and state_closed entries within the MQTT Covers but this hasn’t corrected the issue. I’m thinking the MQTT Publish automation payload needs to be adjusted but not sure how. Is there another way I can come at this

Thanks Nick

In your automation do you have data_template:

  action:
  - service: mqtt.publish
    data_template:

or is it data:

  action:
  - service: mqtt.publish
    data:

It has to be data_template

yes I can confirm that data_template is used in my automation file

- alias: 'MQTTGarageDoor2'
  trigger:
    platform: state
    entity_id: binary_sensor.2_garage_door
  action:
  - service: mqtt.publish
    data_template:
      topic: 'home/garagedoor2'
      payload: "{{ 'open' if trigger.payload == 'on' else 'closed' }}"

below I have added an excerpt from my HA log which shows

  • the binary sensor registered successfully
  • the mqtt published item “MQTTGarageDoor2” executing
  • can see the mqtt component transmitting messages
  • can also see the mqtt complement received messages but this is where the “payload is not True or False” is logged

Log file:

2019-03-29 08:19:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Received {'type': 'call_service', 'domain': 'cover', 'service': 'open_cover', 'service_data': {'entity_id': 'cover.pergolarollerdoor'}, 'id': 25}
2019-03-29 08:19:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=cover, service=open_cover, service_data=entity_id=cover.pergolarollerdoor>
2019-03-29 08:19:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=cmnd/rollerdoor2/POWER, qos=0, retain=False, payload=1>
2019-03-29 08:19:04 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on cmnd/rollerdoor2/POWER: 1
2019-03-29 08:19:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Sending {'id': 25, 'type': 'result', 'success': True, 'result': None}
2019-03-29 08:19:16 INFO (MainThread) [homeassistant.components.http.view] Serving /api/ to 172.30.32.2 (auth: True)
2019-03-29 08:19:16 INFO (MainThread) [homeassistant.components.http.view] Serving /api/konnected/device/bcddc282716d to 192.168.11.21 (auth: True)
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=<state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:10:28.418894+11:00>, new_state=<state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:19:16.173406+11:00>>
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.2_garage_door_state, old_state=<state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T08:10:28.459862+11:00>, new_state=<state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T08:19:16.177415+11:00>>
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=MQTTGarageDoor2, entity_id=automation.mqttgaragedoor2>
2019-03-29 08:19:16 INFO (MainThread) [homeassistant.components.automation] Executing MQTTGarageDoor2
2019-03-29 08:19:16 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Running script
2019-03-29 08:19:16 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Executing step call service
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=home/garagedoor2, payload=closed>
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774446920] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': <state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:10:28.418894+11:00>, 'new_state': <state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:19:16.173406+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 19, 16, 173454, tzinfo=<UTC>), 'context': {'id': '2e98d3a0c3924c0daf725e670178cddc', 'user_id': None}}}
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': <state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:10:28.418894+11:00>, 'new_state': <state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:19:16.173406+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 19, 16, 173454, tzinfo=<UTC>), 'context': {'id': '2e98d3a0c3924c0daf725e670178cddc', 'user_id': None}}}
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on home/garagedoor2: closed
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774446920] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': <state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T08:10:28.459862+11:00>, 'new_state': <state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T08:19:16.177415+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 19, 16, 177566, tzinfo=<UTC>), 'context': {'id': '209c8148a37e4bd9adde725ecccf2c5b', 'user_id': None}}}
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': <state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T08:10:28.459862+11:00>, 'new_state': <state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T08:19:16.177415+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 19, 16, 177566, tzinfo=<UTC>), 'context': {'id': '209c8148a37e4bd9adde725ecccf2c5b', 'user_id': None}}}
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home/garagedoor2: b'closed'
2019-03-29 08:19:16 WARNING (MainThread) [homeassistant.components.mqtt.cover] Payload is not True or False:
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.mqttgaragedoor2, old_state=<state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:10:28.620919+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:10:13.404221+11:00>, new_state=<state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:19:16.241423+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:10:13.404221+11:00>>
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774446920] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:10:28.620919+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:10:13.404221+11:00>, 'new_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:19:16.241423+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:10:13.404221+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 19, 16, 241913, tzinfo=<UTC>), 'context': {'id': '2e98d3a0c3924c0daf725e670178cddc', 'user_id': None}}}
2019-03-29 08:19:16 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:10:28.620919+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:10:13.404221+11:00>, 'new_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:19:16.241423+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:10:13.404221+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 19, 16, 241913, tzinfo=<UTC>), 'context': {'id': '2e98d3a0c3924c0daf725e670178cddc', 'user_id': None}}}

2019-03-29 08:47:25 INFO (MainThread) [homeassistant.components.http.view] Serving /api/konnected/device/bcddc282716d to 192.168.11.21 (auth: True)
2019-03-29 08:47:26 INFO (MainThread) [homeassistant.components.http.view] Serving /api/konnected/device/bcddc282716d to 192.168.11.21 (auth: True)
2019-03-29 08:47:27 INFO (MainThread) [homeassistant.components.http.view] Serving /api/konnected/device/bcddc282716d to 192.168.11.21 (auth: True)
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=<state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:47:17.649052+11:00>, new_state=<state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:47:27.046574+11:00>>
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.2_garage_door_state, old_state=<state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T08:47:17.655655+11:00>, new_state=<state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T08:47:27.052132+11:00>>
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774446920] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': <state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:47:17.649052+11:00>, 'new_state': <state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:47:27.046574+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 47, 27, 46622, tzinfo=<UTC>), 'context': {'id': 'ded71c17a7a647e29e09651000de96e1', 'user_id': None}}}
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': <state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:47:17.649052+11:00>, 'new_state': <state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T08:47:27.046574+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 47, 27, 46622, tzinfo=<UTC>), 'context': {'id': 'ded71c17a7a647e29e09651000de96e1', 'user_id': None}}}
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=MQTTGarageDoor2, entity_id=automation.mqttgaragedoor2>
2019-03-29 08:47:27 INFO (MainThread) [homeassistant.components.automation] Executing MQTTGarageDoor2
2019-03-29 08:47:27 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Running script
2019-03-29 08:47:27 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Executing step call service
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=home/garagedoor2, payload=closed>
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on home/garagedoor2: closed
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774446920] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': <state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T08:47:17.655655+11:00>, 'new_state': <state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T08:47:27.052132+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 47, 27, 52221, tzinfo=<UTC>), 'context': {'id': '815d6d5bf24540a1879b68a216a4e3cb', 'user_id': None}}}
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': <state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T08:47:17.655655+11:00>, 'new_state': <state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T08:47:27.052132+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 47, 27, 52221, tzinfo=<UTC>), 'context': {'id': '815d6d5bf24540a1879b68a216a4e3cb', 'user_id': None}}}
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.mqttgaragedoor2, old_state=<state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:47:17.700163+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:24:37.012208+11:00>, new_state=<state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:47:27.098160+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:24:37.012208+11:00>>
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774446920] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:47:17.700163+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:24:37.012208+11:00>, 'new_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:47:27.098160+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:24:37.012208+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 47, 27, 98727, tzinfo=<UTC>), 'context': {'id': 'ded71c17a7a647e29e09651000de96e1', 'user_id': None}}}
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.139916774372744] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:47:17.700163+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:24:37.012208+11:00>, 'new_state': <state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T08:47:27.098160+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T08:24:37.012208+11:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 28, 21, 47, 27, 98727, tzinfo=<UTC>), 'context': {'id': 'ded71c17a7a647e29e09651000de96e1', 'user_id': None}}}
2019-03-29 08:47:27 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home/garagedoor2: b'closed'
2019-03-29 08:47:27 WARNING (MainThread) [homeassistant.components.mqtt.cover] Payload is not True or False:

I don’t understand why it reports that message … but it is significant.

Let’s try a few small changes and see if it behaves the same way or differently.
I’ve identified the suggested changes in the examples below. Basically we are switching from using open/closed to 1/0.

- alias: 'MQTTGarageDoor2'
  trigger:
    platform: state
    entity_id: binary_sensor.2_garage_door
  action:
  - service: mqtt.publish
    data_template:
      topic: 'home/garagedoor2'
      payload: '{{ "1" if trigger.payload == "on" else "0" }}'  # <-- changed to numeric states

CORRECTION
Later in this thread I discovered the source of my error. This is the correct template for payload:

      payload: '{{ "1" if trigger.to_state_state == "on" else "0" }}'

- platform: mqtt
  name: "pergolarollerdoor"
  state_topic: "home/garagedoor2"
  command_topic: "cmnd/rollerdoor2/POWER"
  availability_topic: "tele/rollerdoor2/LWT"
  payload_available: "Online"
  payload_not_available: "Offline"
  payload_open: "1"
  payload_close: "1"
  payload_stop: "1"
  state_open: "1" # <--- changed from open to 1
  state_closed: "0" #<-- changed from closed to 0

Thank you for your quick reply

I have added the requested code adjustment and the messages have cleared so I think we are getting closer but I still don’t see the state change on the cover arrow and the state is unknown

image
image
image

I can see in the log the state changing but it is not reporting

When the door is open
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=<state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T10:29:48.317591+11:00>, new_state=<state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:11:01.006140+11:00>>

When the door is closed
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=<state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:24:41.207344+11:00>, new_state=<state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:26:04.562516+11:00>>

Log excerpt of when the door is going from open to close

2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=&lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T10:29:48.317591+11:00&gt;, new_state=&lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:11:01.006140+11:00&gt;&gt;
2019-03-29 11:11:01 INFO (MainThread) [homeassistant.components.http.view] Serving /api/konnected/device/bcddc282716d to 192.168.11.21 (auth: True)
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=&lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T10:29:48.317591+11:00&gt;, new_state=&lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:11:01.006140+11:00&gt;&gt;
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=sensor.2_garage_door_state, old_state=&lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T10:29:48.321485+11:00&gt;, new_state=&lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:11:01.011786+11:00&gt;&gt;
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event automation_triggered[L]: name=MQTTGarageDoor2, entity_id=automation.mqttgaragedoor2&gt;
2019-03-29 11:11:01 INFO (MainThread) [homeassistant.components.automation] Executing MQTTGarageDoor2
2019-03-29 11:11:01 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Running script
2019-03-29 11:11:01 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Executing step call service
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event call_service[L]: domain=mqtt, service=publish, service_data=topic=home/garagedoor2, payload=0&gt;
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013356957480] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': &lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T10:29:48.317591+11:00&gt;, 'new_state': &lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:11:01.006140+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 11, 1, 6197, tzinfo=&lt;UTC&gt;), 'context': {'id': '70bb3508bdd84a589335596ac381cbd9', 'user_id': None}}}
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013333860592] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': &lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T10:29:48.317591+11:00&gt;, 'new_state': &lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:11:01.006140+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 11, 1, 6197, tzinfo=&lt;UTC&gt;), 'context': {'id': '70bb3508bdd84a589335596ac381cbd9', 'user_id': None}}}
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on home/garagedoor2: 0
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013356957480] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': &lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T10:29:48.321485+11:00&gt;, 'new_state': &lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:11:01.011786+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 11, 1, 11844, tzinfo=&lt;UTC&gt;), 'context': {'id': 'fe512433b18046d6a112c3f751a32a94', 'user_id': None}}}
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013333860592] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': &lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T10:29:48.321485+11:00&gt;, 'new_state': &lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:11:01.011786+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 11, 1, 11844, tzinfo=&lt;UTC&gt;), 'context': {'id': 'fe512433b18046d6a112c3f751a32a94', 'user_id': None}}}
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home/garagedoor2: b'0'
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=automation.mqttgaragedoor2, old_state=&lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T10:29:48.357522+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;, new_state=&lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:11:01.047682+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;&gt;
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013356957480] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T10:29:48.357522+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;, 'new_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:11:01.047682+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 11, 1, 48079, tzinfo=&lt;UTC&gt;), 'context': {'id': '70bb3508bdd84a589335596ac381cbd9', 'user_id': None}}}
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013333860592] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T10:29:48.357522+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;, 'new_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:11:01.047682+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 11, 1, 48079, tzinfo=&lt;UTC&gt;), 'context': {'id': '70bb3508bdd84a589335596ac381cbd9', 'user_id': None}}}

Log excerpt of when the door is going from close to open

2019-03-29 11:26:02 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013334420448] Received {'type': 'call_service', 'domain': 'cover', 'service': 'open_cover', 'service_data': {'entity_id': 'cover.pergolarollerdoor'}, 'id': 19}
2019-03-29 11:26:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event call_service[L]: domain=cover, service=open_cover, service_data=entity_id=cover.pergolarollerdoor&gt;
2019-03-29 11:26:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event call_service[L]: domain=mqtt, service=publish, service_data=topic=cmnd/rollerdoor2/POWER, qos=0, retain=False, payload=1&gt;
2019-03-29 11:26:02 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on cmnd/rollerdoor2/POWER: 1
2019-03-29 11:26:02 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013334420448] Sending {'id': 19, 'type': 'result', 'success': True, 'result': None}
2019-03-29 11:26:04 INFO (MainThread) [homeassistant.components.http.view] Serving /api/konnected/device/bcddc282716d to 192.168.11.21 (auth: True)
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=&lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:24:41.207344+11:00&gt;, new_state=&lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:26:04.562516+11:00&gt;&gt;
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=sensor.2_garage_door_state, old_state=&lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:24:41.210046+11:00&gt;, new_state=&lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T11:26:04.572297+11:00&gt;&gt;
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event automation_triggered[L]: name=MQTTGarageDoor2, entity_id=automation.mqttgaragedoor2&gt;
2019-03-29 11:26:04 INFO (MainThread) [homeassistant.components.automation] Executing MQTTGarageDoor2
2019-03-29 11:26:04 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Running script
2019-03-29 11:26:04 INFO (MainThread) [homeassistant.helpers.script] Script MQTTGarageDoor2: Executing step call service
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event call_service[L]: domain=mqtt, service=publish, service_data=topic=home/garagedoor2, payload=0&gt;
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013333860592] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': &lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:24:41.207344+11:00&gt;, 'new_state': &lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:26:04.562516+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 26, 4, 562571, tzinfo=&lt;UTC&gt;), 'context': {'id': '2df0dec855d6459e8eca1a10a48bb4c9', 'user_id': None}}}
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013334420448] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'binary_sensor.2_garage_door', 'old_state': &lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:24:41.207344+11:00&gt;, 'new_state': &lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:26:04.562516+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 26, 4, 562571, tzinfo=&lt;UTC&gt;), 'context': {'id': '2df0dec855d6459e8eca1a10a48bb4c9', 'user_id': None}}}
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on home/garagedoor2: 0
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013333860592] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': &lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:24:41.210046+11:00&gt;, 'new_state': &lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T11:26:04.572297+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 26, 4, 572369, tzinfo=&lt;UTC&gt;), 'context': {'id': '3b69bdbb9f04473d9174f25fb46f41e0', 'user_id': None}}}
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013334420448] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.2_garage_door_state', 'old_state': &lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:24:41.210046+11:00&gt;, 'new_state': &lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T11:26:04.572297+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 26, 4, 572369, tzinfo=&lt;UTC&gt;), 'context': {'id': '3b69bdbb9f04473d9174f25fb46f41e0', 'user_id': None}}}
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on home/garagedoor2: b'0'
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=automation.mqttgaragedoor2, old_state=&lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:24:41.248256+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;, new_state=&lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:26:04.622673+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;&gt;
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013333860592] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:24:41.248256+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;, 'new_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:26:04.622673+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 26, 4, 623091, tzinfo=&lt;UTC&gt;), 'context': {'id': '2df0dec855d6459e8eca1a10a48bb4c9', 'user_id': None}}}
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140013334420448] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'automation.mqttgaragedoor2', 'old_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:24:41.248256+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;, 'new_state': &lt;state automation.mqttgaragedoor2=on; last_triggered=2019-03-29T11:26:04.622673+11:00, friendly_name=MQTTGarageDoor2 @ 2019-03-29T10:26:17.165458+11:00&gt;}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 3, 29, 0, 26, 4, 623091, tzinfo=&lt;UTC&gt;), 'context': {'id': '2df0dec855d6459e8eca1a10a48bb4c9', 'user_id': None}}}

In both cases, (‘open to close’ and ‘close to open’) the automation publishes the same payload: 0.

2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on home/garagedoor2: 0


2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on home/garagedoor2: 0

What does that mean? It means the value_template is always failing to match trigger.payload == "on" and reporting 0.

payload: '{{ "1" if trigger.payload == "on" else "0" }}'

Please look at Home Assistant’s States page, find binary_sensor.2_garage_door in the list, operate the garage door and watch the sensor change states. It should change from off to on to off. I need to confirm the sensor is operating properly and its states are on and off.

Yes I can confirm that the binary_sensor.2_garage_door is changing state

Sensor from on to off

entity_id=binary_sensor.2_garage_door, old_state=<state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T10:29:48.317591+11:00>, new_state=<state binary_sensor.2_garage_door=off

2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=&lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T10:29:48.317591+11:00&gt;, new_state=&lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:11:01.006140+11:00&gt;&gt;
2019-03-29 11:11:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=sensor.2_garage_door_state, old_state=&lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T10:29:48.321485+11:00&gt;, new_state=&lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:11:01.011786+11:00&gt;&gt;

Sensor from off to on

entity_id=binary_sensor.2_garage_door, old_state=<state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:24:41.207344+11:00>, new_state=<state binary_sensor.2_garage_door=on;

2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=binary_sensor.2_garage_door, old_state=&lt;state binary_sensor.2_garage_door=off; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:24:41.207344+11:00&gt;, new_state=&lt;state binary_sensor.2_garage_door=on; friendly_name=2 Garage Door, device_class=door @ 2019-03-29T11:26:04.562516+11:00&gt;&gt;
2019-03-29 11:26:04 DEBUG (MainThread) [homeassistant.core] Bus:Handling &lt;Event state_changed[L]: entity_id=sensor.2_garage_door_state, old_state=&lt;state sensor.2_garage_door_state=Closed; friendly_name=2_garage_door_state, entity_picture=/local/garage.png @ 2019-03-29T11:24:41.210046+11:00&gt;, new_state=&lt;state sensor.2_garage_door_state=Open; friendly_name=2_garage_door_state, entity_picture=/local/garage-open-blue.png @ 2019-03-29T11:26:04.572297+11:00&gt;&gt;

I think I figured it out. I made a mistake in the template!

The trigger is using platform: state but I specified the wrong triggering syntax in the template.

It should be this:

payload: '{{ "1" if trigger.to_state.state == "on" else "0" }}'

This should be the correct version of the automation:

- alias: 'MQTTGarageDoor2'
  trigger:
    platform: state
    entity_id: binary_sensor.2_garage_door
  action:
  - service: mqtt.publish
    data_template:
      topic: 'home/garagedoor2'
      payload: '{{ "1" if trigger.to_state.state == "on" else "0" }}'