'Subscribe to MQTT events.
This method must be run in the event loop and returns a coroutine.'

def async_added_to_hass(self):

    @callback
    def message_received(topic, payload, qos):
        'Handle    new    MQTT    messages.'
        if ((self._expire_after is not None) and (self._expire_after > 0)):
            if self._expiration_trigger:
                self._expiration_trigger()
                self._expiration_trigger = None
            expiration_at = (dt_util.utcnow() + timedelta(seconds=self._expire_after))
            self._expiration_trigger = async_track_point_in_utc_time(self.hass, self.value_is_expired, expiration_at)
        if (self._template is not None):
            payload = self._template.async_render_with_possible_json_value(payload, self._state)
        self._state = payload
        self.hass.async_add_job(self.async_update_ha_state())
    return mqtt.async_subscribe(self.hass, self._state_topic, message_received, self._qos)
