How can I get the HA state machine to recognize my garage door's state?

Home Assistant receives a JSON string via MQTT each time one of my garage doors changes state. The door state is a text field, and may be any one of the following:
“Open”, “Closed”, “Opening”, “Closing”, “Stopped”, or “Unknown”.

How do I get Home Assistant’s state machine to store the current state so that I can create automations triggered by a state transition like from: Closed, to: Opening?

This is how to decode JSON values for your sensor, which I think is what you are asking for.

Also, you might be interested in this, which will allow you to define a cover entity from disparate sensors and switches

These are the sensors that I currently have defined.

########## Garage Door 1 state & stateMsg
  - platform: mqtt
    state_topic: "doorminder/data"
    name: garage_door1_state
    value_template: "{{ value_json.gnode.doors.0.state }}"
    retain: true

  - platform: mqtt
    state_topic: "doorminder/data"
    name: garage_door1_statemsg
    value_template: "{{ value_json.gnode.doors.0.message }}"
    retain: true

The above allows me to display:

  • The current state as it is defined by my garage door controller (Open, Closed, Opening, Closing, Stoped, or Unknown)
  • The message generated by the my garage door controller(which normally displays the day, date, and time of the last state change, but will display “beeping …” when the controller is warning anyone inside the garage that someone has remotely triggered a door action, or “signal sent …” when the controller actually signals the door opener to perform an action.)

That is all working perfectly.

My current goal is to have Google Home broadcast a message when specific door state transitions occur. I had expected to be able to use the states as defined by my garage door controller but it seems that Home Assistant only recognizes “state” as a “binary” or “numeric value”.

In this specific case, I only care about the transitions to and from the “Closed” state, so I decided to create a new binary sensor that I can use in my automation. After some syntax wrestling, I got this to work:

  - platform: mqtt
    state_topic: "doorminder/data"
    name: garage_door1_secure
    value_template: "{% if value_json.gnode.doors.0.state == 'Closed' %}on{% else %}off{% endif %}"
    payload_on: "on"
    payload_off: "off"
    retain: true